PrinterCE.NetCF Developer's Guide
Namespace : FieldSoftware.PrinterCE_NetCF
DLLs : PrinterCE_NetCF.dll, PrCE_NetCF.dll
Class Name: PrinterCE
PrinterCE for .Net CF provides the .Net CF software developer with tools to add printing capabilities to C# and VB.Net apps. applications developed in Microsoft抯 CE Studio. The PrinterCE.NetCF module contains the following print classes:
| PrinterCE for .NetCF: The primary class for printing text, images, drawing objects (lines, rectangles, etc) and much more. |
| AsciiCE for .NetCF: A separate class that allows for printing pure ASCII text to any ASCII printer. |
| BarcodeCE for .NetCF: An optional class derived from PrinterCE that adds over a dozen barcode types to PrinterCE. |
Simple C# code for using the PrinterCE class to print out "Hello World":
PrinterCE prce = null;
try
{
prce = new PrinterCE(); //Create instance of PrinterCE class
prce.SelectPrinter(true);
prce.DrawText("Hello World"); //Print "Hello World" on page
prce.EndDoc(); //Done with this page - print it
}
catch (PrinterCEException exc) {
if (prce!=null)
{
prce.ShutDown(); //Done - free PrinterCE resources
prce=null;
}
prce=null;
MessageBox.Show("PrinterCE Exception","Exception");
}
finally
{
if (prce!=null)
{
prce.ShutDown(); //Done - free PrinterCE resources
prce=null;
}
}
PrinterCE for NetCF Constructors
Create an instance of PrinterCE using one of the following 4 overloaded versions:
Syntax: (4 overloaded versions):
public PrinterCE();
public PrinterCE(string initstr);
public PrinterCE(EXCEPTION_LEVEL exclevel);
public PrinterCE(EXCEPTION_LEVEL exclevel,string initstr);
Parameters
initstr- Developer's License Key used to unlock PrinterCE. Default is for PrinterCE to run in evaluation mode. After evaluation time limit has expired on a device, PrinterCE will be locked and will not function.
exclevel - Sets level of errors that will cause an exception, using EXCEPTION_LEVEL enumeration:
EXCEPTION_LEVEL Enumeration | Description |
NONE | PrinterCE will not throw an exception - use StatusCheck to determine if an error has occurred. |
ABORT_JOB | PrinterCE throws an exception if the print job is aborted, either by serious error or user cancel. Certain error conditions that affect only the a specific function will not throw an exception. For example, if DrawPicture is called with an image file that cannot be found or is not a valid image file type. |
ALL (default) | PrinterCE throws an exception for any error found. |
Example:
PrinterCE prce1 = new PrinterCE(PrinterCE.EXCEPTION_LEVEL.ABORT_JOB,"YOURLICENSEKEY");
//No License Key for evaluation
Remarks
If exception handling is enabled, PrinterCE throws a "PrinterCEException" exception for exception errors found. To catch any PrinterCE, BarcodeCE or AsciiCE thrown exception use:
catch (PrinterCEException exc) {...
With exception handling disabled, when an error occurs within PrinterCE , the severity of the error is determined and PrinterCE "remembers" this as appropriate and the host app uses StatusCheck to determine if an error condition was found.
For example, if a printer error occurs, the entire printing job must be aborted, so all calls to PrinterCE will remember that it is aborting and this will be handled gracefully. This design allows the app that uses PrinterCE to have a relaxed approach to error handling, even to the point of ignoring errors completely (although it would be kind to the user to do StatusCheck calls and display error dialog boxes as needed).
PrinterCE for NetCF Methods and Properties
READ-ONLY property returns string describing this version of PrinterCE
Syntax: stringaboutstr=PrinterCE1.About
Returns
String describing this version of PrinterCE - including information on WinCE platform, processor type and version. This string can be used in a MessageBox to display the information - MessageBox.Show(PrinterCE1.About,"PrinterCE Version");
Example
MessageBox.Show(PrinterCE1.About,"PrinterCE Version");
ConvertCoord
This method converts a value from one ScaleMode system to another.
Syntax:
double ConvertCoord(double val, MEASUREMENT_UNITS fromscalemode,
MEASUREMENT_UNITS toscalemode);
MEASUREMENT_UNITS Enumeration | Description |
TWIPS | 1440 Twips per inch |
POINTS | 72 points per inch |
PIXELS | Printer resolution - for example 300 dpi |
INCHES | Inches |
MILLIMETERS | Millimeters |
CENTIMETERS | Centimeters |
Parameters
fromval - Value to be converted
fromscale - "convert from" MEASUREMENT_UNITS
toscale - "convert to" MEASUREMENT_UNITS.
Returns
toval - Converted value.
Example:
To convert 1.25 inches into printer resolution:
double PrResVal=PrinterCE1.ConvertCoord(1.25,PrinterCE.MEASUREMENT_UNITS.INCHES,
PrinterCE.MEASUREMENT_UNITS.PIXELS);
DrawCircle
Prints a circle or ellipse on a page.
Syntax: (4overloaded versions):
void DrawCircle(double x,double y,double radius);
void DrawCircle(double x,double y,double radius,Color pen color);
void DrawCircle(double x,double y,double radius,double aspect);
void DrawCircle(double x,double y,double radius,Color pen color,
double aspect);
Parameters
x - Horizontal coordinate for the center point of a circle.
y - Vertical coordinate for the center point of a circle.
radius - Radius of a circle.
color � color of a circle's outline. Default is ForeColor value
aspect � aspect ratio of a circle. The default value is 1.0, which yields a perfect circle. Other values draw an ellipse. (Also see DrawEllipse for another way to draw ellipses).
Remarks
The ScaleMode property of object determines the units of measure used.
The FillColor and FillStyle properties of object determine how a circle is filled.
The DrawWidth property determines the width of the line used to draw a circle.
DrawEllipse
Prints an ellipse on a page.
Syntax (2 overloaded versions):
void DrawEllipse(double x1,double y1,double x2,double y2);
void DrawEllipse(double x1,double y1,double x2,double y2,Color pencolor);
Parameters
x1, y1, x2, y2 - Values define a rectangle (x1,y1) as one corner and (x2,y2) as
opposing corner. An ellipse is drawn that just fits within this bounding rectangle.
color � color of a circle's outline. Default is ForeColor value
Remarks
The ScaleMode property of object determines the units of measure used.
The FillColor and FillStyle properties of object determine how a circle is filled.
The DrawWidth property determines the width of the line used to draw a circle.
DrawLine
Prints a line.
Syntax (2 overloaded versions):
void DrawLine(double x1,double y1,double x2,double y2);
void DrawLine(double x1,double y1,double x2,double y2,Color pencolor);
Parameters
x1, y1 - starting coordinates for a line or rectangle
x2, y2 - ending coordinates for a line or rectangle.
color � Color used to draw a line. Default is ForeColor value.
Remarks
The DrawWidth property determines the width of the line.
The ScaleMode property determines the unit of measure used.
DrawPicture
Prints a BMP, JPG, GIF or PNG image file on the page. Note: A few non-Pocket PC devices may not include full image support (BMP should always be supported). You can test your device to verify what file types are supported.
Syntax (2 overloaded versions):
void DrawPicture(string picture, double x, double y);
void DrawPicture(string picture, double x, double y,
double width, double height,bool keepaspect);
Parameters
picture : Path & filename of the image to be drawn.
x,y : Coordinates where picture will be drawn (in ScaleMode units). By default, x,y is the top/left corner of the image location. Use JustifyHoriz/JustifyVert to change this to Center or Bottom/Right.
width : Destination width of picture. Default (or if width==0): actual image width
height : Destination height of picture. Default (or if height==0): actual image height is used.
keepaspect : If true, retains aspect ratio (width to height of original image)... image is sized to fit inside of "width" x "height".
Remarks
If width and/or height are negative values, DrawPicture creates a mirror image along the vertical axis (if width is negative) and/or the horizontal axis (if height is negative). See: GetPictureDims() to get actual image width and height.
DrawPoint
Print a point on the page.
Syntax (2 overloaded versions):
void DrawPoint(double x,double y);
void DrawPoint(double x,double y,Color pencolor);
Parameters
x, y - Coordinates of the point to draw (in ScaleMode units)
color - Color used to draw the point. Default is ForeColor value.
Remarks
DrawWidth property determines the size of the point.
DrawRect
Prints a rectangle on a page.
Syntax (2 overloaded versions):
void DrawRect(double x1,double y1,double x2,double y2);
void DrawRect(double x1,double y1,double x2,double y2,Color pencolor);
Parameters
x1, y1, x2, y2 - defines a rectangle with (x1,y1) as one corner and (x2,y2) as opposing corner
color - Color used to draw the rectangle. Default is ForeColor value.
Remarks
Coordinates are in ScaleMode units.
FillColor and FillStyle properties of object determine how a rectangle is filled.
DrawWidth property determines the width of the line used to draw a rectangle.
DrawRoundedRect
Prints a rectangle with rounded corners on a page.
Syntax (2 overloaded versions):
void DrawRoundedRect(double x1,double y1,double x2,double y2,
double corner_width,double corner_height);
void DrawRoundedRect(double x1,double y1,double x2,double y2,
double corner_width,double corner_height,Color pencolor);
Parameters
x1, y1, x2, y2 - Defines a rectangle with (x1,y1) as one corner and (x2,y2) as opposing corner.
cornerwidth,cornerheight - defines the width and height of the curve of the rounded rectangle..
color - Color used to draw the rectangle. Default is ForeColor value.
Remarks
Coordinates are in ScaleMode units.
FillColor and FillStyle properties of object determine how a rectangle is filled.
DrawWidth property determines the width of the line used to draw a rectangle.
DrawText
Prints text on the page. (See also DrawTextFlow).
Syntax (4 overloaded versions):
void DrawText(string drawstr);
void DrawText(string drawstr,double x,double y);
void DrawText(string drawstr,Int32 ccnt);
void DrawText(string drawstr,double x,double y,Int32 ccnt);
Parameters
string - Text to be drawn.
x, y - Coordinates of the text to be drawn. Default: string is drawn at the intrinsic (TextX,TextY) coordinates.
ccnt- Number of characters in "string" that should be printed Default: entire line of text is printed.
Remarks
The font properties of the PrinterCE control determines the appearance of the text.
The ForeColor property determines the color of the text.
After the text is drawn, TextX, TextY are updated so that the next DrawText command will print on a new line.
The JustifyHoriz, JustifyVert, and Rotation properties all impact how and where the text is actually drawn on the page.
Coordinates are in ScaleMode units
DrawTextFlow (*Exclusive to PrinterCE.NetCF SDK)
Flows printed text on the page, optionally handling word wrap and page breaks automatically. For sample code visit here.
Syntax (4 overloaded versions):
int DrawTextFlow(string drawstr);
int DrawTextFlow(string drawstr,FLOW_OPTIONS flowtype);
int DrawTextFlow(string drawstr,double left,double top,double width,double height,
int ccnt,FLOW_OPTIONS flowtype);
int DrawTextFlow(string drawstr,double x,double y,double left,double top,
double width,double height,int ccnt,FLOW_OPTIONS flowtype);
Parameters
drawstr - Text to be drawn.
x, y - Coordinates of the position within the "drawing box" for the top left corner of the start of the text.
Defaults to x, y coordinates of most recent DrawText/DrawTextFlow call. Pass -1 to use default values
left, top, width, height - Defines a "drawing box" within which the text will be flowed on the page.
Defaults to left and top margins with full page width and height. Pass -1 to use default values.
ccnt - Number of characters in text string to print. Defaults to all text string. Pass -1 to use default.
flowtype - Bit flags to enable/disable Draw Flow options (OR these together)
FLOW_OPTIONS Enumeration | Description |
DEFAULT | Default "flow" working mode: auto word-wrap, auto page break (form feed) |
NOWORDWRAP | Prints one line of text, determining where to break the text string. Returns number of characters printed. |
NOFORMFEED | Prints text, flowing in "drawing box" as appropriate. If reaches the bottom of the "drawing box", stops printing and returns total number of characters printed. |
NOENDINGLINEFEED | Normal operation after flowing text into the "drawing box" is to move to the start of the next line (CR/LF). Using NOENDINGLINEFEED causes (x, y) coordinates to be left immediately after the end of the last character printed. |
HARDBREAK | Normal operation is for DrawTextFlow to try to "break" a line of text in a natural flow, such as at a space. Use HARDBREAK to fit all text possible onto each line, with break made after the last character that will fit. |
Return
Returns number of characters printed during DrawTextFlow operation.
Remarks
- JustifyHoriz and Rotation properties are ignored - DrawTextFlow always draws LEFT justified in NORTH rotation.
- JustifyVert is used to determine vertical justification.
- The ForeColor property determines the color of the text.
- Coordinates are in ScaleMode units
DrawWidth
Property: Returns / sets the line width in ScaleMode uints for output from a graphics method. A size of 0 sets line width to 1 pixel.
Syntax:
get: double wid = PrinterCE1.DrawWidth;
set: PrinterCE1.DrawWidth = (double) wid;
EndDoc
Begin printing the current page, then reset printing properties to default.
Syntax: void EndDoc();
FillColor
Property: Returns / sets the color used to fill in graphics methods: DrawRect, DrawRoundedRect, DrawCircle and DrawEllipse. By default, FillColor is set to 0 (Black).
Examples:
get: Color wid = PrinterCE1.FillColor;
set: PrinterCE1.FillColor = Color.Blue;
Remarks
When the FillStyle property is set to Transparent (default), the FillColor setting is ignored.
FillStyle
Property: Returns / sets the pattern used to fill in graphics methods: DrawRect, DrawRoundedRect, DrawCircle and DrawEllipse. Use FILL_STYLE enumeration:
FILL_STYLE Enumaration | Description |
SOLID | Solid |
TRANSPARENT | Transparent (default) |
Examples:
get: PrinterCE.FILL_STYLE style = PrinterCE1.FillStyle;
set: PrinterCE1.FillStyle= PrinterCE.FILL_STYLE.SOLID;
Remarks
When the FillStyle property is set Transparent, the FillColor setting is ignored. For more selective settings, see FontBoldVal property.
FontBold
Property: Returns / sets the Bold font style to true (Bold ON) or false (Bold OFF);
Examples:
get: bool isbold = PrinterCE1.FontBold;
set: PrinterCE1.FontBold=true;
FontBoldVal
Property: Returns / sets the current font's Bold weight.
Examples:
get: int boldweight = PrinterCE1.FontBoldVal;
set: PrinterCE1.FontBoldVal=850;
Parameters
value - Integer value between 0 and 1000 to set the weight of the font. Normal weight setting is 400 and standard Bold is 700.
FontItalic
Property: Returns / sets the Italic font style to true (Italic ON) or false (Italic OFF);
Examples:
get: bool isitalic = PrinterCE1.FontItalic;
set: PrinterCE1.FontItalic=true;
FontName
Property: Returns / sets the font used to print text.
Examples:
get: string fontname = PrinterCE1.FontName;
set: PrinterCE1.FontName="Courier New";
Remarks
Any TrueType font can be used. To install a TrueType font to the device, simply copy from desktop PC to /Windows/Fonts folder on the device. You can use Pocket Word -> Edit -> Format -> pull down list of available fonts to see exact font names of all installed fonts.
FontSize
Property: Returns / sets the point size of the font to be used for printing.
Examples:
get: int fontsize = PrinterCE1.FontSize;
set: PrinterCE1.FontSize=14; //Set font size to 14 point
Remarks
Note: to match a point size with equivalent point size of Microsoft Word, use negative point size... for example, to match Word's 12 point font, use PrinterCE1.FontSize = -12.
Max is 2,160 points, min is 4 points. There are 72 points per inch.
FontStrikethru
Property: Returns / sets the Strikethrough style, true = Strikethrough ON, false OFF
Examples:
get: bool isstrikethru = PrinterCE1.FontStrikethru;
set: PrinterCE1.FontStrikethru=true;
FontUnderline
Property: Returns / sets the Underline font style. true = Underline ON, false is OFF
Examples:
get: bool isunderline = PrinterCE1.FontUnderline;
set: PrinterCE1.FontUnderline=true;
ForeColor
Property: Returns / sets the foreground color used to print text. Default is Color.Black
Examples:
get: Color forecolor = PrinterCE1.ForeColor;
set: PrinterCE1.ForeColor=Color.Red;
GetLastErr (*Exclusive to PrinterCE.NetCF SDK)
ERROR GetLastErr - Read-only property - returns last error type for PrinterCE.NetCF:
ERROR Enumeration | Description |
NONE | No current error |
PRINT_TASK | Unable to complete printing task. |
USER_CANCELLED | Print operation cancelled by user |
OUTOFMEMORY | Not enough memory to complete the task |
INVALID_ARGUMENT | Invalid argument to PrinterCE.NetCF call |
ABORT | Unknown error |
PRINTER_DIALOG | Print Dialog error |
FONT | Couldn't create font. |
IMAGE | Unable to load image. |
PRINTER_SETTINGS | Check printer settings (page size, margins, etc) |
INFRARED | Unable to establish Infrared link |
COMMUNICATION_LINK | Unable to establish link to printer |
COMMUNICATION_LOST | Lost communications link to printer |
DIALOG | Dialog error... cannot continue |
NETWORK | Unable to print across the network. |
NET_NOWNET | Network support functions for network printing not found on this device. |
NET_CHECKALL | Unable to connect to computer or find network printers. Check computer name and network connection. |
NET_NOSERVER | Network unavailable or this device does not support network printing. |
BLUETOOTH | Unable to connect with Bluetooth printer... Use Bluetooth Manager to discover your printer and connect it to Serial Port. Verify that Bluetooth Radio is ON. |
Example:
PrinterCE.ERROR errtype = PrinterCE1.GetLastErr;
if (errtype == PrinterCE.ERROR.USERCANCELLED) {
//Handle user cancel situation
}
GetPictureDims (*Exclusive to PrinterCE.NetCF SDK)
This method returns width and height of an image in an image file in ScaleMode units.
Syntax: bool GetPictureDims(string picture,out double width,out double height);
Parameters
picture : Path & filename of the image to be drawn.
width: Actual width of image
height: Actual height of image
Returns: true if valid picture found.
GetStringHeight
READ-ONLY Property - Returns the height of the current font in ScaleMode units
Syntax: double ht = PrinterCE1.GetStringHeight;
GetStringWidth
Returns the width of the given text string (in ScaleMode units)
Syntax: double wid = PrinterCE1.GetStringWidth("TextString");
Returns version of PrinterCE.NetCF - forms major.minor.build.revision
Syntax: void GetVersion(out int major,out int minor,out int build,out int revision);
IsColor
READ-ONLY property returns TRUE if current selected printer can print color.
Syntax: bool usescolor = PrinterCE1.IsColor;
Property: Returns / sets the horizontal justification (left, center, right) of following DrawText and DrawImage methods.
JUSTIFY_HORIZ Enumeration |
LEFT (Default) |
CENTER |
RIGHT |
Examples:
get: PrinterCE.JUSTIFY_HORIZ hjust = PrinterCE1.JustifyHoriz;
set: PrinterCE1.JustifyHoriz=PrinterCE.JUSTIFY_HORIZ.CENTER;
Property: Returns / sets the vertical justification (top, center, bottom) of following DrawText and DrawImage methods.
JUSTIFY_VERT Enumeration |
TOP (Default) |
CENTER |
BOTTOM |
Examples:
get: PrinterCE.JUSTIFY_VERT vjust = PrinterCE1.JustifyVert;
set: PrinterCE1.JustifyVert=PrinterCE.JUSTIFY_VERT.BOTTOM;
KillDoc
Abort the current page - Flush all print operations and reset printing properties to default.
Syntax: void KillDoc();
NewPage
Begin printing the current page then prepare for another page of printing commands. Do not reset printing properties to default.
Syntax: void NewPage();
PgIndentLeft
Property: Returns / sets an indent from the left margin of the page where the start of the horizontal printing is found. The value is in printer resolution dots (see PrinterResolution).
Examples:
get: int curleftindent = PrinterCE1.PgIndentLeft;
set: PrinterCE1.PgIndentLeft=300; //Set left indent 300 dots from margin
Remarks
The PgIndentLeft and PgIndentTop settings can be called multiple times while printing one page. All subsequent drawing methods use the new settings. Use this technique to easily print multiple columns and/or rows of items.
PgIndentTop
Property: Returns / sets an indent from the top margin of the page where the start of the vertical printing is found. The value is in printer resolution dots (see PrinterResolution).
Examples:
get: int curtopindent = PrinterCE1.PgIndentTop;
set: PrinterCE1.PgIndentTop=300; //Set top indent 300 dots from margin
Remarks
The PgIndentLeft and PgIndentTop settings can be called multiple times while printing one page. All subsequent drawing methods use the new settings.
PrBottomMargin
Property: Returns / sets the bottom margin of the page. The value is in ScaleMode units.
Examples:
get: double curBottomMgn = PrinterCE1.PrBottomMargin;
set: PrinterCE1.PrBottomMargin = (double) 0.75;
Property: Returns / sets the action of the "Printing in progress" dialog box (which allows the user to cancel the print operation).
DIALOGBOX_ACTION Enumeration | Description |
UP | Display "in progress" dialog box |
DOWN | Take down dialog box |
DISABLE | Prevent dialog box from being used |
STATUS | Display status of printing operation |
DEBUG_ON | Uses "in progress" dialog box to show details about internal mode of PrinterCE during printing. (Off by default). |
DEBUG_OFF | Turns off Debug mode. |
Examples:
get: PrinterCE.DIALOGBOX_ACTION dbox = PrinterCE1.PrDialogBox;
set: PrinterCE1.PrDialogBox = PrinterCE.DIALOGBOX_ACTION.UP;
Remarks
By default, the "Printing in progress" dialog box is displayed with the first call by VB to a PrinterCE page operation (such as Select Printer, Draw Object, etc). This dialog box will remain until EndDoc or KillDoc completes the printing job. Calling PrDialogBox(vbDlgDisable) will prevent PrinterCE from displaying the dialog box (and will not give the user any chance to cancel).
See PrDialogBoxText() to change the text displayed or language used by this dialog.
This method allows changing the text displayed or language used by the "Printing in progress" dialog box.
Syntax: void PrDialogBoxText(string MainText,string TitleText,
string CancelBtnText);
Parameters
MainStr - String for main text portion of the "Printing in progress" dialog box.
TitleStr - String for title portion of the "Printing in progress" dialog box.
CancelBtnStr - String for Cancel Button portion of the "Printing in progress" dialog box
Remarks
The text of this dialog box may be changed at any time� if the dialog box is already displayed, it will be taken down, the new text added, and then the dialog box will be redisplayed. If the dialog box is not currently displayed, it will remain down until a call to PrDialogBox() or until PrinterCE automatically displays it.
PrinterResolution
READ-ONLY property returns "dots per inch" resolution of currently selected printer
Syntax: int prRes = PrinterCE1.PrinterResolution;
PrLeftMargin
Property: Returns / sets the left margin of the page. The value is in ScaleMode units.
Examples:
get: double curLeftMgn = PrinterCE1.PrLeftMargin;
set: PrinterCE1.PrLeftMargin = (double) 0.75;
PrRightMargin
Property: Returns / sets the right margin of the page. The value is in ScaleMode units.
Examples:
get: double curRightMgn = PrinterCE1.PrRightMargin;
set: PrinterCE1.PrRightMargin = (double) 0.75;
PrSetDefaults
This method causes the printer control to reset all printer-specific values to the printer defaults.
Syntax: void PrinterCE1.PrSetDefaults();
PrTopMargin
Property: Returns / sets the top margin of the page. The value is in ScaleMode units.
Examples:
get: double curTopMgn = PrinterCE1.PrTopMargin;
set: PrinterCE1.PrTopMargin = (double) 0.75;
PrOrientation
This property returns and sets the orientation of the printed page using the ORIENTATION enumeration.
ORIENTATION Enumeration | Description |
PORTRAIT | Normal page orientation |
LANDSCAPE | Page rotated landscape |
Example: PrinterCE1.PrOrientation=PrinterCE.ORIENTATION.LANDSCAPE;
PrPaperSelection
Property: Returns / sets the paper selection for the printed page using PAPER_SELECTION enum:
PAPER_SELECTION Enumeration |
LETTER |
A4 |
B5 |
LEGAL |
CUSTOM |
Examples:
get: PrinterCE.PAPER_SELECTION ptype = PrinterCE1.PrPaperSelection;
set: PrinterCE1.PrPaperSelection= PrinterCE.PAPER_SELECTION.LETTER;
PrPgHeight
READ-ONLY Property - Returns the current height in ScaleMode units of the printable area of the page (after subtracting out Top & Bottom margins).
Example:
get: double pght = PrinterCE1.PrPgHeight;
PrPgWidth
READ-ONLY Property - Returns the current width in ScaleMode units of the printable area of the page (after subtracting out Left & Right margins).
Example:
get: double pgwid = PrinterCE1.PrPgWidth;
PrPrintQuality
Property: Returns / sets the quality of the printing � High vs Draft using PRINT_QUALITY enum:
PRINT_QUALITY Enumeration |
HIGH |
DRAFT |
Examples:
get: PrinterCE.PRINT_QUALITY ptype = PrinterCE1.PrPrintQuality;
set: PrinterCE1.PrPrintQuality = PrinterCE.PRINT_QUALITY.HIGH;
Remarks
Many printers do not support DRAFT "print quality".
Rotation
Property: Returns / sets the rotation of subsequent text and image drawing commands using ROTATION_TYPE enumeration:
ROTATION_TYPE Enumeration | Description |
NORTH | Rotation is 0 degrees |
EAST | Rotation is 90 degrees clockwise |
SOUTH | Rotation is 180 degrees |
WEST | Rotation is 270 degrees clockwise |
Examples:
get: PrinterCE.ROTATION_TYPE rot = PrinterCE1.Rotation;
set: PrinterCE1.Rotation= PrinterCE.ROTATION_TYPE.SOUTH;
Remarks
Images and text can be printed at 90 degree rotations and intermixed freely on the same page. For example, you can print a text string in the default rotation North, call the Rotation method = 180 and then print another string upside-down.
The trickiest part of using Rotation is getting a mental image of how the text strings and images will be positioned on a page. For example, if you have justification set to Left and Top justify the usage of TextX and TextY will be used to justify the text string or image based on the rotation setting.
Property: Returns / sets the unit of measurement for coordinates of printing objects using MEASUREMENT_UNITS Enumeration:
MEASUREMENT_UNITS Enumeration | Description |
TWIPS (Default) | 1,440 twips per inch. 567 twips per centimeter |
POINTS | 72 points per logical inch |
PIXELS | Smallest unit of printer resolution - see PrinterResolution |
INCHES |
|
MILLIMETERS |
|
CENTIMETERS |
|
Examples:
get: PrinterCE.MEASUREMENT_UNITS scale = PrinterCE1.ScaleMode;
set: PrinterCE1.ScaleMode= PrinterCE.MEASUREMENT_UNITS.INCHES;
SelectPrinter
Method pops up the Select Printer dialog box to allow the user to select the printer and printer options to be used for printing.
Syntax: void SelectPrinter(bool StartPrinting);
Parameter
StartPrinting - If true, includes "Start Printing" button on the dialog box and attempts to establish communication with printer if user taps this. If false, uses "Save Settings" button instead and saves user settings to registry when tapped (exclusive to PrinterCE.NetCF).
Remarks
If SelectPrinter is never called, the default printer and settings are used.
Write-Only property sets error level of errors reported to user by PrinterCE.NetCF. NOTE: The SetReportLevel setting will not affect the Exception Level set by PrinterCE.NetCF constructor (see here for Exception Level info).
Set report level using REPORT_LEVEL enumeration:
REPORT_LEVEL Enumeration | Description |
ALL_ERRORS (Default) | All errors and user cancel are reported to user by PrinterCE via error dialog |
SERIOUS_ERRORS | All errors are reported, but user cancel will not show "Are you sure" message box prompt. |
NO_ERRORS | No errors are reported to user... it is up to app to report errors. However, if user presses Cancel during print they will see "Are you sure" prompt. |
NO_ERRORS_SKIP_CANCEL | No errors are reported to user. If user presses Cancel, no "Are you sure" prompt is given. |
Example:
set: PrinterCE1.SetReportLevel=PrinterCE.REPORT_LEVEL.NO_ERRORS;
Set IP address and port for networked print server. SetupNetIPPrinter must be called before calling SetupPrinter().
Syntax: void SetupNetIPPrinter(string netstr,int port,bool OpenPort);
Parameters
netstr - IP address string
port - IP port value
OpenPort - true if want to establish communication link immediately
Example: prce.SetupNetIPPrinter("192.168.0.234",9101,false);
Set IP address and port for networked print server. SetupNetIPPrinter must be called before calling SetupPrinter(). SetupNetSharedPrinter must be called before calling SetupPrinter().
Syntax: void SetupNetSharedPrinter(string netstr,bool OpenPort);
Parameters
netstr - Network path string to shared printer.
OpenPort - true if want to establish communication link immediately
Example: prce.SetupNetSharedPrinter("FieldSoft//HP995c",true);
This establishes connection to printer "HP995c" on networked PC "FieldSoft".
Programmatically set the printer and port settings. (See also SetupAllPrinterSettings).
Syntax: 2 overloaded versions
void SetupPrinter(PRINTER Printer,PORT Port,bool OpenPort);
void SetupPrinter(PRINTER Printer,PORT Port,PORT_SPEED Baudrate,
bool OpenPort);
Parameters
Printer - One of the following PRINTER selections:
Description | |
USE_CURRENT | Use most recently saved printer from registry. |
ABLE_AP1300 | Able Systems Ap1300 |
AXIOHM_A631 | Axiohm A631 |
BROTHER | Brother MPrint |
CANONBJ360 | Canon BubbleJet compatible printers (360 dpi) |
CANONBJ600 | Canon PIXMA iP90, i80, i70 |
CANONBJ300 | Canon BubbleJet 300 dpi |
CITIZEN_203 | Citizen 203DPI printers |
CITIZEN_CMP10 | Citizen CMP-10 |
CITIZEN_PD22 | Citizen PD-22 |
CITIZEN_PD04 | Citizen PD-04, PD-24 |
CITIZEN_PN60 | Citizen PN60i |
ELTRADE | Eltrade Mobilife |
EPSON_ESCP2 | Epson ESC/P 2 compatible printers |
EPSON_STYLUS | Epson Stylus compatible printers |
EPSON_TM_P60 | Epson TM-P60 |
EXTECH_2 | Extech 2" Thermal |
EXTECH_3 | Extech 3" Thermal |
EXTECH_4 | Extech 4" Thermal |
FUJITSU_FTP628 | Fujitsu FTP-628WSL110 |
GEBE_FLASH | GeBE Flash 4" Thermal |
GENERIC24_180 | Generic Epson compatible 180DPI 24-pin printers (LQ/ESC) |
GENERIC24_360 | Generic Epson compatible 360DPI 24-pin printers (LQ/ESC) |
GENERIC24_203 | Generic Epson compatible 203DPI 24-pin printers (LQ/ESC) |
HP_PCL | HP PCL compatible - includes DeskJet and LaserJet |
INTERMEC | Intermec PB/PW/68/78 Thermal |
IPC_PP50 | IPC PP-50 |
IPC_PP55 | IPC PP-55 |
OMNIPRINT | OMNIPrint 6240 and 6400 |
ONEIL | O'Neil MicroFlash |
PANASONIC_JTH200PR | Panasonic JTH200PR |
PENTAX_200 | Pentax PocketJet 3 and PocketJet 200 |
PENTAX_300 | Pentax PocketJet 3 Plus and PocketJet II |
PERIPHERON_NOMAD | Peripheron Nomad |
POCKET_SPECTRUM | Pocket Spectrum |
S_PRINT | CUSTOM s'print |
SATO | SATO MB200i |
SEIKO3445 | Seiko DPU-3445 |
SEIKO_L465 | Seiko DPU-L465 |
TALLY_MIP360 | TallyGenicom MIP360 rugged 24-pin dot matrix printer |
TALLY_MTP4 | TallyGenicom MTP4 4" thermal printers |
ZEBRA | Zebra Cameo, Encore and QL |
SIPIX | SiPix A6 printer |
DYMOCOSTAR | DymoCoStar label printers |
SEIKOLABELWRITER | Seiko LabelWriter printers |
Port - One of the following PORT selections:
Description | |
USE_CURRENT | Use most recently saved port from registry. |
INFRARED | Infrared port |
NETPATH | Print to shared printer on a networked host PC |
NETIP | Print to network IP printer - a printer with its own IP address |
COMPAQ_BT | HP/Compaq Bluetooth iPAQ or sleeve |
IPAQ_BT | HP/Compaq Bluetooth iPAQ or sleeve |
SOCKETCOM_BT | Socket Bluetooth card support |
WIDCOMM_BT | Device using WIDCOMM Bluetooth stack |
COM1 | Com1: serial port |
COM2 | Com2: serial port |
COM3 | Com3: serial port |
COM4 | Com4: serial port |
COM5 | Com5: serial port |
COM6 | Com6: serial port |
COM7 | Com7: serial port |
COM8 | Com8: serial port |
COM9 | Com9: serial port |
TOFILE | Print to file "/OUTPUT.PRN" |
LPT | LPT: parallel port |
BTQUIKPRINT | Special for HP iPAQ/WIDCOMM Bluetooth devices that pop up "Bluetooth Browser" to find/select BT printer at print time: using this flag bypasses the BT browser and uses most recent selected BT printer. To let user discover and select BT printer, use COMPAQ_BT, IPAQ_BT, WIDCOMM_BT |
Baudrate - One of the following PORT_SPEED values. Defaults to USE_CURRENT.
Description | |
USE_CURRENT | Use most recently saved baud rate from registry. |
S_4800 | 4800 baud |
S_9600 | 9600 baud |
S_19200 | 19200 baud |
S_38400 | 38400 baud |
S_57600 | 57600 baud |
S_115200 | 115200 baud |
OpenPort - If true, tries to immediately establish communication with the selected printer and port. If false, delays until ready to send print data.
This method selects paper settings (see also SetupPaperCustom).
Syntax: (2 overloaded versions):
void SetupPaper(PAPER_SELECTION PaperSize,ORIENTATION Orientation);
void SetupPaper(PAPER_SELECTION PaperSize,ORIENTATION Orientation,
double LeftMargin,double TopMargin,double RightMargin,double BottomMargin);
Parameters
PaperSize - One of the following PAPER_SELECTION values:
Description | |
USE_CURRENT | Use most recently saved paper selection from registry. |
LETTER | Letter sized paper |
A4 | A4 paper |
B5 | B5 paper |
LEGAL | Legal-sized paper |
CUSTOM | Custom-sized paper (see SetupPaperCustom as preferred way to set CUSTOM paper). |
Orientation - One of ORIENTATION values:
Description | |
USE_CURRENT | Use most recently saved orientation selection from registry. |
PORTRAIT | Portrait mode |
LANDSCAPE | Landscape (sideways) mode |
LeftMargin, TopMargin, RightMargin, BottomMargin: Sets printing margins in ScaleMode units. Defaults to most recently saved margin values. To leave any margin values unchanged, use -1.0 for margin setting.
This method selects CUSTOM paper type and sets paper size.
Syntax: (2 overloaded versions):
public void SetupPaperCustom(ORIENTATION Orientation,
double CustomPaperWidth,double CustomPaperHeight);
public void SetupPaperCustom(ORIENTATION Orientation,
double CustomPaperWidth,double CustomPaperHeight,double LeftMargin,
double TopMargin,double RightMargin,double BottomMargin);
Parameters
Orientation: See ORIENTATION table.
CustomPaperWidth, CustomPaperHeight - Paper width and height (in ScaleMode units). Maximum values: 22 inches, 56 cm, 32000 twips - note that actual paper width settings depend on printer selection and other factors.
LeftMargin, TopMargin, RightMargin, BottomMargin - Margins used for printed page (in ScaleMode units) Defaults to most recently saved margin values. To leave any margin values unchanged, use -1.0 for margin setting.
This method programmatically sets a variety of "other" printing options (see SetupPrinter, SetupPaper and SetupNet... methods for other printer/paper related settings).
Syntax:
void SetupPrinterOther(FORMFEED_SETTING FFSetting,double FormFeedScrollDistance,
DENSITY Density,SERIAL_HANDSHAKE Handshake,BITFLAG BitFlags,
COMPRESSION Compression,DITHER Dither,PRINTQUALITY PrintQuality);
Parameters
FFSetting- One of the following FormFeed selections:
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
NORMAL | Printer sends formfeed command to printer at end of each page. |
PAPERHEIGHT | PrinterCE scrolls printer to selected paper height. |
SCROLL | PrinterCE will scroll paper by "FormFeedScrollDistance" distance from last printed portion of page. |
FormFeedScrollDistance - Distance (in ScaleMode units) to scroll if FFSetting=FFEED_SCROLL (value of -1.0 keeps current setting).
Density - Darkness/Lightness setting for print density.
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
EXTRALIGHT | Lightest printing |
EXTRALIGHT | Lightest printing |
LIGHTER | Medium light printing |
NORMAL | Normal printing density |
DARKER | Darker printing |
EXTRADARK | Darkest printing |
Handshake - Valid only for serial port selections (COMx) - Defines serial port handshake:
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
SOFTWARE | Uses Xon/Xoff |
HARDWARE | Uses hardware control lines |
NO_HANDSHAKE | No handshaking of serial port. |
BitFlags - Miscellaneous bit settings (OR these together):
BITFLAG Enumeration | Description |
USE_CURRENT | Use most recently saved setting from registry. |
ADJUST_IR | Forces IR (infrared) buffer size to 2040 bytes for Canon BJC printers and to 64 bytes for all other printers... this fixes IR hardware incompatibilities in a few printers. |
ALTERNATE_IR | (Obsolete) There are a few Windows CE devices that have trouble printing through the infrared port to specific printers due to problems in the infrared port driver of the device. This option provides an alternate (generally less robust) approach to IR connection. |
COLOR | Enables color printing for HP PCL, Canon BJC, Epson and other color printers. |
CMYONLY | CMY 3-Color Printing - for color printers that do not have black ink. |
SINGLETHREAD | PrinterCE normally uses two threads (separate processes) for printing. Selecting BITFLAG_SINGLETHREAD forces PrinterCE to use one thread. |
Compression - Select data compression mode for printing:
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
STANDARD | Uses standard printer compression for faster printing (default) |
NONE | No compression - much slower printing. |
Dither - Select Dither or Diffusion technique for image conversion :
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
DIFFUSION | Uses color diffusion (default) |
DITHER | Use dithering |
PrintQuality - Select High Quality vs Draft mode printing (if available). Note: DraftMode is not
supported for many printer types and may not result in any difference.
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
STANDARD | Uses standard quality printing (default) |
DRAFT | Draft mode printing (if available) |
SetupPrSettings_All (*Exclusive to PrinterCE.NetCF SDK)
Method to set or query all printer and paper related settings for PrinterCE.NetCF SDK using PRINTER_SETUP struct:
PRINTER_SETUP structure (not in this order):
PRINTER Printer;
PORT Port;
PORT_SPEED PortSpeed;
PAPER_SELECTION PaperSelection;
ORIENTATION Orientation;
FORMFEED_SETTING FormFeedSetting;
DENSITY Density;
SERIAL_HANDSHAKE SerialHandshake;
COMPRESSION Compression;
DITHER Dither;
PRINTQUALITY PrintQuality;
ADJUST_IR AdjustIR;
OTHER_IR OtherIR;
COLOR_MONO ColorMono;
THREAD Thread;
Int32 IP_port; //See SetupNetIPPrinter
double LeftMargin,TopMargin,RightMargin,BottomMargin; //See SetupPaperSize
double CustomPaperWidth,CustomPaperHeight; //See SetupPaperCustom
double FormFeedScrollDistance; //See FormFeedScrollDistance
String SharedPrinter_NetStr; //See SetupNetSharedPrinter
String IP_NetStr; //See SetupNetIPPrinter
Example:
// Get current printer settings from PrinterCE.NetCF
PrinterCE.PRINTER_SETUP prsettings = prce.SetupPrSettings_All;
//Make a few changes...
prsettings.Printer=PrinterCE.PRINTER.EPSON_ESCP2;
prsettings.SharedPrinter_NetStr="FieldSoft//MyPr";
prsettings.PaperSelection=PrinterCE.PAPER_SELECTION.A4;
prsettings.TopMargin=0.66;
//Save the new settings back to PrinterCE.NetCF
prce.SetupPrSettings_All=prsettings;
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
STANDARD | Uses standard IR buffers size (default) |
OPTIONAL | Forces IR (infrared) buffer size to 2040 bytes for Canon BJC printers and to 64 bytes for all other printers... this fixes IR hardware incompatibilities in a few printers. |
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
STANDARD | Uses standard IR support (default) |
OPTIONAL | (Obsolete) There are a few Windows CE devices that have trouble printing through the infrared port to specific printers due to problems in the infrared port driver of the device. This option provides an alternate (generally less robust) approach to IR connection. |
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
MONOCHROME | Set printer to monochrome (non-color) |
CMYK_4COLOR | Set to print in color for printers with 4 ink colors (Cyan, Magenta, Yellow and Black). |
CMY_3COLOR | Set to print in color for printers with 3 ink colors (Cyan, Magenta and Yellow). |
Description | |
USE_CURRENT | Use most recently saved setting from registry. |
MULTIPLE | Uses separate print thread for enhanced printing performance (default) |
SINGLE | Use single thread for PrinterCE.NetCF functionality. |
ShutDown
Method: Frees system resources when PrinterCE instance is being destroyed. Note: It is not necessary to call ShutDown if the PrinterCE instance is global and lasts for the lifetime of your app. Only call ShutDown if PrinterCE instance is about to be destroyed.
Example:
PrinterCE prce = null;
try
{
prce = new PrinterCE(); //Create instance of PrinterCE class
//... various PrinterCE printing commands called here
prce.EndDoc(); //Done with this page - print it
}
catch (PrinterCEException exc)
{
MessageBox.Show("PrinterCE Exception","Exception");
}
finally
{
if (prce!=null)
{
prce.ShutDown(); //PrinterCE about to go away - free PrinterCE resources
}
prce=null;
}
READ-ONLY property: returns the current status of PrinterCE. See also SetExceptionLevel and SetReportLevel.
Syntax: PRINT_STATUSStatusCheck();
Returns
PRINT_STATUS Enumeration | Description |
NO_ERROR | No error to report |
USER_CANCEL | User cancelled print job |
ABORT_OPERATION | Error aborted the last print operation (but the print job is still viable). |
ABORT_PRINT | Error aborted the print job |
Remarks
The AbortOperation status is momentary� if a "DrawPicture" method cannot find the specified image file, that operation is aborted and a call to StatusCheck that follows the DrawPicture method will return vbAbortOperation. However, if a successful DrawText operation immediately follows the aborted DrawPicture call, a call to StatusCheck after DrawText will return vbNoError..
TextX
Property: Returns / sets the current X coordinate for text positioning in ScaleMode units. The next DrawText method call will use this coordinate to position its text (unless DrawText overrides it with an X coordinate in the method).
Examples:
get: double curX = PrinterCE1.TextX;
set: PrinterCE1.TextX=2.5;
Remarks
Actual position of the text is impacted by the JustifyHoriz/JustifyVert and Rotation property settings. TextX is measured from the Left margin setting. TextX and TextY are automatically adjusted after every DrawText call to move to the next line of text. This allows for automatic printing of multiple lines of text. The amount moved is dependent on the FontSize (point size) of the text. The direction of movement is dependent on the Rotation property setting
TextY
Property: Returns / sets the current Y coordinate for text positioning in ScaleMode units. The next DrawText method call will use this coordinate to position its text (unless DrawText overrides it with an Y coordinate in the method).
Examples:
get: double curY = PrinterCE1.TextY;
set: PrinterCE1.TextY=2.5;
Remarks
Actual position of the text is impacted by the JustifyHoriz/JustifyVert and Rotation property settings. TextY is measured from the Left margin setting. TextX and TextY are automatically adjusted after every DrawText call to move to the next line of text. This allows for automatic printing of multiple lines of text. The amount moved is dependent on the FontSize (point size) of the text. The direction of movement is dependent on the Rotation property setting
相关组件下载:
http://download.youkuaiyun.com/source/2453674