.NET API: Developer support tool

The StarMicronics.CloudPRNT Utility package offers an API that implements Star CloudPRNT-compatible servers.


Built based on the .NET Standard 2.0 specifications, this API can be used freely in the following applications:

  • .NET Framework 4.6.1 or later
  • .NET Core 2.0 or later


The StarMicronics.CloudPRNT Utility package offers the following functions that support CloudPRNT server developers:


This language is designed to be used as a utility class set for CloudPRNT server development. However, status decoding and document format conversion are useful in applications, especially ones where the Star Document Markup language is used for printing.


For details on each class and type, refer to API References. Inline help is available (in English only) for IDEs, such as Visual Studio and Visual Studio Code.


This .NET API library has not been tested in the following .NET environments (including versions other than the below):

  • Mono version 5.4
  • Xamarin.iOS Version 10.14
  • Xamarin.Mac Version 3.8
  • Xamarin.Android Version 8.0
  • UWP Version 10.0.16299
  • Unity Version 2018.1

.NET API Installation

Installation in Visual Studio


1 On the Solution Explorer panel, right-click the project and select [Manage NuGet Packages] to display the NuGet dialog box.


2 Click "Browse".


3 Enter StarMicronics.CloudPRNT-Utility in the search box to search for the package.


4 Select the appropriate version (the latest version is recommended).


5 Click "Installed".


If the project meets the .NET Standard 2.0 compatibility requirements*, the package and its dependencies are installed on the project.
*.NET Framework 4.6.1 or NET Core 2.0 or later

Installation with the dotnet Command


1 Open the command prompt and type "cd" to go to the project folder (a folder containing the project ".csproj" file).


2 Execute the following dotnet command:

dotnet add package StarMicronics.CloudPRNT-Utility

If the project targets .NET implementation compatible with .NET Standard 2.0, this API package and its dependencies are installed.

Installing to a project

StarMicronics.CloudPRNT-Utility is provided as a NuGet package, and can be installed via the Visual Studio NuGet UI, the nuget command line utility, or dotnet command line utility.

Notes on Library Versions :
<V1.1.0 or earlier>
StarMicronics.CloudPRNT-Utility package uses the prerelease version of SixLabors.ImageSharp for image processing at this time and has been evaluated by V1.0.0-beta0007. Therefore the specification about image processing in API is possiblliy subject to change without notice. And if failed to install the StarMicronics.CloudPRNT-Utility, please install "SixLabors.ImageSharp" package by "Manage NuGet packages..."(check "including pre-release") at first.
<V1.1.1>
StarMicronics.CloudPRNT-Utility package uses the release version of SixLabors.ImageSharp for image processing at this time and has been evaluated by V1.0.2.
<V1.1.2 or later>
StarMicronics.CloudPRNT-Utility package uses the release version of SixLabors.ImageSharp for image processing at this time and has been evaluated by V1.0.4.


How to Use the .NET API

All elements in the StarMicronics.CloudPRNT Utility package can be used in the namespace "StarMicronics.CloudPRNT."
The provided API classes are assumed to be used mainly in processing CloudPRNT POST/GET requests when adding CloudPRNT support as the functional enhancement of an existing service.

When receiving a CloudPRNT poll through an HTTP POST request


When receiving CloudPRNT job data through an HTTP GET request

  • The server uses one of the input data formats (PNG, JPEG, BMP, GIF, text, and Star Document Markup) supported by the API to retrieve or render the print job.
  • The server needs to prepare the StarMicronics.CloudPrnt.ConversionOptions object and determine the print job preparation method (whether to use dithering and scaling when printing an image, etc.).
  • The server uses the StarMicronics.CloudPrnt.Document static helper method Convert() or ConvertFromFile() to convert the source document (print job source) into the media type requested by the CloudPRNT client device.


Serialization Classes

Under the namespace StarMicronics.CloudPRNT.CpMessage, there are classes to serialize and deserialize CloudPRNT poll JSON messages.

The following two major classes are available:


The simple CloudPRNT server method of processing CloudPRNT poll requests is as follows: (For C#)

string HandleCloudPRNTPoll(string request)
{ 
	PollRequest pollRequest = PollRequest.FromJson(request);
	Console.WriteLine(
		String.Format("Received CloudPRNT request from {0}, status: {1}",
		pollRequest.printerMAC,
		pollRequest.statusCode
	));

	// Create a response object
	PollResponse pollResponse = new PollResponse();

	// do not print anything at this time
	pollResponse.jobReady = false
	pollResponse.mediaTypes = null;

	return JsonConvert.SerializeObject(pollResponse);
}




Decoding the Status

StarMicronics.CloudPrnt.PrinterStatusclass provides a method to easily decode and verify the Start ASB format status to be returned from the Star CloudPRNT client.

The printer device status reported from the CloudPRNT client is decoded into a hexadecimal string according to the Star ASB specifications.
The following is an example:

"23 86 00 00 00 00 00 00 00 00 00"


This can be decoded into an easy-to-process form using the PrinterStatus class.
To use this class, pass the status string as a constructor string as follows:

PrinterStatus status = new PrinterStatus("23 86 00 00 00 00 00 00 00 00 00");
 if(status.CoverOpen)
 	Console.WriteLine("Printer cover is open");


If the code already has the PollRequest object, you can use the PollRequest.DecodedStatus property to acquire the PrinterStatus object.

PollRequest pollRequest = PollRequest.FromJson(request);
 if(pollRequest.DecodedStatus.CoverOpen)
	Console.WriteLine("Printer cover is open");



Determining the Output Media Types Available for a Print Job

Print documents are processed through classes that implement the ICpDocument interface.
There are currently three document core types supported by the API.


The above ICpDocument implementation converts input documents into appropriate output formats to ensure that they can be processed by any Star printer.
You can directly configure each document type, but it is normally easier to use the static StarMicronics.CloudPrnt.Document class, which provides the factory method. By creating a document object, you can completely hide the use of the ICpDocument class.

The easiest way to retrieve a list of output media types supported for specific input is the Document.GetOutputTypesFromType(string) or Document.GetOutputTypesFromFileName(string) method.

For example, if server implementation uses Star Document Markup to prepare for a print job, the API determines which data format it can be converted into.

string[] availableOutputMediaTypes = Document.GetOutputTypesFromType("text/vnd.star.markup");


If a job is provided through a file, you can tell available output types by its file name (an identifiable file extension is required).

string[] availableOutputMediaTypes = Document.GetOutputTypesFileName("jobs/order.png");


The following is an example of a CloudPRNT POST request handler:

string HandleCloudPRNTPoll(string request)
{
	PollRequest pollRequest = PollRequest.FromJson(request);
	Console.WriteLine(
		String.Format("Received CloudPRNT request from {0}, status: {1}",
			pollRequest.printerMAC,
			pollRequest.statusCode
		));

	// Create a response object
	PollResponse pollResponse = new PollResponse();

	if (database.jobAvailable(pollRequest.printerMAC))
	{
		pollResponse.jobReady = true;
		pollResponse.mediaTypes = new List<string>();
		pollResponse.mediaTypes.AddRange(Document.GetOutputTypesFromType("text/vnd.star.markup");
	}
	else
 	{
 		pollResponse.jobReady = false;
 		pollResponse.mediaTypes = null;
 	}

 	return pollResponse.ToJson();
}

Note that the above example uses the database object to maintain the status and requirements of a specific device.



Converting and Providing Print Job Data (GET Request)

When the server notifies that a print job is available and provides a list of available media types (through a poll response), the CloudPRNT device requests the actual print job data through HTTP GET.

Before downloading the print job, the client device first selects the priority media type for job encoding and then executes HTTP GET by passing the selected media type as a part of a query string.
The server can provide the print job in any format by ignoring the requested media type. The client device prints the data only when its format is supported. However, this method is not recommended.
Note that no data format is guaranteed to be supported by all client devices.

To ensure compatibility with all CloudPRNT client devices, it is recommended that the server always generate a GET response with the requested media type.
The server uses the StarMicronics.CloudPrnt.Document.Convert() or StarMicronics.CloudPrnt.Document.ConvertFromFile() method to execute this conversion.

The following is an example of creating a print job with Star Document Markup and converting it into a format requested by the client device:

// Make a simple markup language job
StringBuilder job = new StringBuilder();
job.Append("Hello World!\n");
job.Append("[barcode: type code39; data 12345; height 10mm]\n");
job.Append("[cut]");
byte[] jobData = Encoding.UTF8.GetBytes(job.ToString());

// get the requested output media type from the query string
string outputFormat = context.Request.Query["type"];

// set the response media type, and output the converted job to the response body
context.Response.ContentType = outputFormat;
Document.Convert(jobData, "text/vnd.star.markup", context.Response.Body, outputFormat, null);

This sample code is assumed to be placed in a CloudPRNT GET handler on the server, and context is a valid .NET Core HTTP Context object (which means that context.Response.Body is an output stream that provides a GET response).
The last parameter is for the ConversionsObject class and is used as the default with null (this is not recommended for a production environment because all output is formatted in 80 mm).