Show / Hide Table of Contents

Class Document

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

Inheritance
System.Object
Document
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StarMicronics.CloudPrnt
Assembly: cs.temp.dll.dll
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 Name 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 Name 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 Name 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 Name 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 StringFile Format
image/bmpBMP compatible image data. Will cause a ImageDoc to be returned.
image/pngPNG compatible image data. Will cause a ImageDoc to be returned.
image/jpegJpeg compatible image data. Will cause a ImageDoc to be returned.
image/gifGif compatible image data. Will cause a ImageDoc to be returned.
text/plainPlain UTF8/Ascii text data. Will cause a TextDoc to be returned.
text/vnd.star.markupUTF8 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 Name 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 StringFile Format
image/bmpBMP compatible image data. Will cause a ImageDoc to be returned.
image/pngPNG compatible image data. Will cause a ImageDoc to be returned.
image/jpegJpeg compatible image data. Will cause a ImageDoc to be returned.
image/gifGif compatible image data. Will cause a ImageDoc to be returned.
text/plainPlain UTF8/Ascii text data. Will cause a TextDoc to be returned.
text/vnd.star.markupUTF8 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 Name 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 document object will be determined by checking the file name extension.

Recognised filename extensions are:

Media Type StringFile Format
.bmpA BMP compatible image file. Will cause a ImageDoc to be returned.
.pngA PNG compatible image file. Will cause a ImageDoc to be returned.
.jpgA Jpeg compatible image file. Will cause a ImageDoc to be returned.
.jpegA Jpeg compatible image file. Will cause a ImageDoc to be returned.
.gifA Gif compatible image file. Will cause a ImageDoc to be returned.
.txtA plain text data file, with UTF8 encoding. Will cause a TextDoc to be returned.
.stmA UTF8 encoded text file containing Star Document Markup commands. Will cause a MarkupDoc to be returned.
Declaration
public static ICpDocument GetDocumentFromFile(string filename)
Parameters
Type Name Description
System.String filename

Name of input file, with valid file extension.

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 StringFile Format
image/bmpA BMP compatible image file. Will cause a ImageDoc to be returned.
image/pngA PNG compatible image file. Will cause a ImageDoc to be returned.
image/jpegA Jpeg compatible image file. Will cause a ImageDoc to be returned.
image/gifA Gif compatible image file. Will cause a ImageDoc to be returned.
text/plainA plain text data file, with UTF8 encoding. Will cause a TextDoc to be returned.
text/vnd.star.markupA UTF8 encoded text file containing Star Document Markup commands. Will cause a MarkupDoc to be returned.
Declaration
public static ICpDocument GetDocumentFromFile(string filename, string mediaType)
Parameters
Type Name Description
System.String filename

Name of the input file.

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", "image/jpeg");

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 Name Description
System.String fileName

Name of an input file.

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 Name 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"));
In This Article
Back to top