Document

The Document class provides some helper/factory methods for opening a document from file or stream and obtaining the correct ICpDocument class.

NameSpace: StarMicronics.CloudPrnt

Syntax

public static class Document

Methods

Convert(Byte[], String, Stream, String, ConversionOptions)

Convert print job data from the supplied buffer and media format, to the requested output stream and media format.

Declaration

public static void Convert(byte[] inputBuffer, string inputType, Stream outputStream, string outputType, ConversionOptions options)

Parameters

Type

ame

Description

System.Byte[]

inputBuffer

Input data buffer.

System.String

inputType

Type of data to be loaded from the input stream, specified as an IANA/MIME style media type.

System.IO.Stream

outputStream

Stream to write the converted output data.

System.String

outputType

Format of the output data, specified as an IANA/MIME style media type.

ConversionOptions

options

Conversion options to specify conversion parameters and output results.

Convert(Stream, String, Stream, String, ConversionOptions)

Convert print job data from the supplied input stream and media format, to the requested output stream and media format.

Declaration

public static void Convert(Stream inputStream, string inputType, Stream outputStream, string outputType, ConversionOptions options)

Parameters

Type

ame

Description

System.IO.Stream

inputStream

Input data stream.

System.String

inputType

Type of data to be loaded from the input stream, specified as an IANA/MIME style media type.

System.IO.Stream

outputStream

Stream to write the converted output data.

System.String

outputType

Format of the output data, specified as an IANA/MIME style media type.

ConversionOptions

options

Conversion options to specify conversion parameters and output results.

ConvertFile(String, Stream, String, ConversionOptions)

Load a file, convert it as needed and output to the requested output stream and media format.
Input data format will be determined based on the file name extension.

Declaration

public static void ConvertFile(string fileName, Stream outputStream, string outputType, ConversionOptions options)

Parameters

Type

ame

Description

System.String

fileName

Input file name.

System.IO.Stream

outputStream

Stream to write the converted output data.

System.String

outputType

Format of the output data, specified as an IANA/MIME style media type.

ConversionOptions

options

Conversion options to specify conversion parameters and output results.

ConvertFile(String, String, Stream, String, ConversionOptions)

Load a file, convert it as needed and output to the requested output stream and media format.

Declaration

public static void ConvertFile(string fileName, string inputType, Stream outputStream, string outputType, ConversionOptions options)

Parameters

Type

ame

Description

System.String

fileName

Input file name.

System.String

inputType

Type of data to be loaded from the input stream, specified as an IANA/MIME style media type.

System.IO.Stream

outputStream

Stream to write the converted output data.

System.String

outputType

Format of the output data, specified as an IANA/MIME style media type.

ConversionOptions

options

Conversion options to specify conversion parameters and output results.

GetDocument(Byte[], String)

Create an ICpDocument object based on an binary byte buffer, using a specified media type to determine the type of ICpDocument.

Supported media types are:

Media Type String

File Format

image/bmp

BMP compatible image data. Will cause a ImageDoc to be returned.

image/png

PNG compatible image data. Will cause a ImageDoc to be returned.

image/jpeg

Jpeg compatible image data. Will cause a ImageDoc to be returned.

image/gif

Gif compatible image data. Will cause a ImageDoc to be returned.

text/plain

Plain UTF8/Ascii text data. Will cause a TextDoc to be returned.

text/vnd.star.markup

UTF8 encoded text data containing Star Document Markup commands. Will cause a MarkupDoc to be returned.

Input will be from the inputData read posiion until the end of the decodable input data (where that can be determined), or until the end of the Stream.

Declaration

public static ICpDocument GetDocument(byte[] inputData, string mediaType)

Parameters

Type

ame

Description

System.Byte[]

inputData

Data to be decoded into an ICpDocument.

System.String

mediaType

Format of the input file as an IANA/MIME style media type.

Returns

Type

Description

ICpDocument

An object implementing ICpDocument, which can be used to prepare the input file for printing via CloudPRNT, including conversion as needed.

Examples
To generate an ICpDocument object based on a simpls Star Document Markup input.
StringBuilder job = new StringBuilder();
job.Append("Hello World!\n");
job.Append("[barcode: type code39; data 12345; height 10mm]\n");
job.Append("[cut]");

byte[] data = Encoding.UTF8.GetBytes(job.ToString());

ICpDocument doc = Document.GetDocument(data, "text/vnd.star.markup");

GetDocument(Stream, String)

Create an ICpDocument object based on an input Stream, using a specified media type to determine the type of ICpDocument.

Supported media types are:

Media Type String

File Format

image/bmp

BMP compatible image data. Will cause a ImageDoc to be returned.

image/png

PNG compatible image data. Will cause a ImageDoc to be returned.

image/jpeg

Jpeg compatible image data. Will cause a ImageDoc to be returned.

image/gif

Gif compatible image data. Will cause a ImageDoc to be returned.

text/plain

Plain UTF8/Ascii text data. Will cause a TextDoc to be returned.

text/vnd.star.markup

UTF8 encoded text data containing Star Document Markup commands. Will cause a MarkupDoc to be returned.

Input will be from the inputStream read posiion until the end of the decodable input data (where that can be determined), or until the end of the Stream.

Declaration

public static ICpDocument GetDocument(Stream inputStream, string mediaType)

Parameters

Type

ame

Description

System.IO.Stream

inputStream

Readable stream.

System.String

mediaType

Format of the input file as an IANA/MIME style media type.

Returns

Type

Description

ICpDocument

An object implementing ICpDocument, which can be used to prepare the input file for printing via CloudPRNT, including conversion as needed.

GetDocumentFromFile(String)

Create an ICpDocument object based on an input file.
The type of ICpDocument object will be determined by checking the file name extension.

Recognised filename extensions are:

Media Type String

File Format

.bmp

A BMP compatible image file. Will cause a ImageDoc to be returned.

.png

A PNG compatible image file. Will cause a ImageDoc to be returned.

.jpg

A Jpeg compatible image file. Will cause a ImageDoc to be returned.

.jpeg

A Jpeg compatible image file. Will cause a ImageDoc to be returned.

.gif

A Gif compatible image file. Will cause a ImageDoc to be returned.

.txt

A plain text data file, with UTF8 encoding. Will cause a TextDoc to be returned.

.stm

A UTF8 encoded text file containing Star Document Markup commands. Will cause a MarkupDoc to be returned.

Input will be from the inputStream read posiion until the end of the decodable input data (where that can be determined), or until the end of the Stream.

Declaration

public static ICpDocument GetDocumentFromFile(string filename)

Parameters

Type

ame

Description

System.String

filename

有効な拡張子付きの入力ファイル名

Returns

Type

Description

ICpDocument

An object implementing ICpDocument, which can be used to prepare the input file for printing via CloudPRNT, including conversion as needed.

Examples
To obtain an ImageDoc object from an input image file.
ICpDocument doc = Document.GetDocumentFromFile("source.jpg");

GetDocumentFromFile(String, String)

Create an ICpDocument object based on an input file, using a specified media type to determine the type of ICpDocument.

Supported media types are:

Media Type String

File Format

.bmp

A BMP compatible image file. Will cause a ImageDoc to be returned.

.png

A PNG compatible image file. Will cause a ImageDoc to be returned.

.jpg

A Jpeg compatible image file. Will cause a ImageDoc to be returned.

.jpeg

A Jpeg compatible image file. Will cause a ImageDoc to be returned.

.gif

A Gif compatible image file. Will cause a ImageDoc to be returned.

.txt

A plain text data file, with UTF8 encoding. Will cause a TextDoc to be returned.

.stm

A UTF8 encoded text file containing Star Document Markup commands. Will cause a MarkupDoc to be returned.

Input will be from the inputStream read posiion until the end of the decodable input data (where that can be determined), or until the end of the Stream.

Declaration

public static ICpDocument GetDocumentFromFile(string filename, string mediaType)

Parameters

Type

ame

Description

System.String

filename

Input file name.

System.String

mediaType

Format of the input file as an IANA/MIME style media type.

Returns

Type

Description

ICpDocument

An object implementing ICpDocument, which can be used to prepare the input file for printing via CloudPRNT, including conversion as needed.

Examples
To obtain an ImageDoc object from an input image file.
ICpDocument doc = Document.GetDocumentFromFile("source.jpg");

GetOutputTypesFromFileName(String)

Get a list of supported output media types for a given input type, determined by input file name.
The type if the input file will be determined simply by checking the filename extension.
And the file will not be opened, read, modified or even checked for existence.

Declaration

public static string[] GetOutputTypesFromFileName(string fileName)

Parameters

Type

ame

Description

System.String

fileName

Input file name.

Returns

Type

Description

System.String[]

A list of output media formats as IANA/MIME media types.

Examples
When handling a CloudPRNT POST (poll) request, to inform a client that a print job is ready for output, when prepared with Star Document Markup format.
CpMessage.PollResponse response = new CpMessage.PollResponse();
response.jobReady = true;
response.mediaTypes = new List<string>();
response.mediaTypes.AddRange(Document.GetOutputTypesFromFieName("test.png"));

GetOutputTypesFromType(String)

Get a list of supported output media types for a given input type.

Declaration

public static string[] GetOutputTypesFromType(string sourceMediaType)

Parameters

Type

ame

Description

System.String

sourceMediaType

The source media type in IANA/MIME form.

Returns

Type

Description

System.String[]

A list of output media formats as IANA/MIME media types.

Examples
When handling a CloudPRNT POST (poll) request, to inform a client that a print job is ready for output, when prepared with Star Document Markup format.
CpMessage.PollResponse response = new CpMessage.PollResponse();
response.jobReady = true;
response.mediaTypes = new List<string>();
response.mediaTypes.AddRange(Document.GetOutputTypesFromType("text/vnd.star.markup"));