Spludlow Web Header

Printing


Contents

Printing in Code. 1

Spludlow Print Language. 1

Printer Types. 1

Print History – Intranet Print Page. 1

Hardware Printer Alignment & Margins. 1

Alignment Problems. 1

Fixing Alignment Problems with Configuration. 1

 

Printing in Code

Most parts of the printing system use strings; font definitions, page sizes, and printer destinations.

Here is a simple example:

       string headFont = "Arial, 32, Bold, Italic, Underline";

       string font = "Times New Roman, 12";

 

       Spludlow.Printing.PrintDoc doc = new Spludlow.Printing.PrintDoc("A4");

 

       doc.Text("Hello World!", headFont, 10, 10);

       doc.Text("The document body test.", font, 10, 40);

 

       //     Print to history only (View in Intranet Print Page)

       Spludlow.Printing.Printer.Print(doc);

 

       //     Print to bitmap files

       Spludlow.Printing.Printer.Print(doc, @"bitmap: D:\TestPrint.png");         //     default 600 dpi

       Spludlow.Printing.Printer.Print(doc, @"bitmap: D:\TestPrint.jpg, 72");  // specify 72 dpi

 

       //     Print to PDF (iTextSharp)

       Spludlow.Printing.Printer.Print(doc, @"pdf: D:\TestPrint.pdf");

 

       //     Print to local printer

       Spludlow.Printing.Printer.Print(doc, "system: canon");

 

       //     Print to remote printer

       Spludlow.Printing.Printer.PrintAt("WSYS-BRAN-APP", doc, "system: 4250, Tray 2");  //     HP 4250 - Tray 2

NOTE: System printer are found by searching using the given name. If anything other than one match is found then an exception is thrown.

Spludlow Print Language

The Framework never prints directly to printers or files; first it saves the print document as text in the “Spludlow Print Language” format. This makes it easy to store print documents for history and reprints.

Printer Types

Once you have your print data you can then print it to one of the following:

·         system

·         bitmap

·         pdf

·         dummy

The “dummy” will not print to anywhere but the document will be stored in the Framework’s print history, so it can be viewed or reprinted from the Print page of the Intranet.

Each printer type will have an associated “PrinterInfo” string describing things like printer names or filenames.

Print History – Intranet Print Page

Print history can be accessed on the Intranet Print page, this allows you to view and reprint anything printed through the framework. Select your host and day and see a list of all documents printed on that day. You can preview pages at the selected DPI, so you can get in close if you have to. You can also reprint either a page or the whole document by selecting a host, printer type, and printer info. When reprinting to a “paper” printer you can select the printer and tray available on the remote host using a drop down list, for file printer types (pdf, bitmap) you need to put the remote filename in a text box.

Reprinting is useful for paper jams, just re-print the bad pages or the whole document. If all the printers in the office are on fire you can reprint to a printer on another network, or print to a file and email someone with a printer.

You can also look back for reported problems without re-printing anything; users often report seeing things that never happened.

When developing document printing code, it’s a waste of time actually printing anything, use the “dummy” printer then preview the pages on the Intranet.

Hardware Printer Alignment & Margins

When printing to a PDF, bitmap, or virtual printer (like the XPS document writer) you can draw anywhere on the page, right into the corners no worries. The page origin starts at the top left of the actual media, everything appears on the page right where you asked for it.

When printing to a hardware printer this is not possible as the printer for whatever technical reason cannot physically print to the entire page. There is an unprintable margin around the whole of the page, the inside of this margin is known as the “Printable Area”.

The printable area will be slightly different on different printers, and may also be different on the same printer using different page orientations and paper sources (trays). Often the horizontal and vertical margin sizes are not the same either, the top margin may be 7mm and the left 5mm for example with the bottom being 6mm.

By default the .net Printing will draw using the top left origin on the printable area’s origin. So everything you draw will left and down by the hardware margins. Why ever this is the default setting I don’t know it’s pretty much a useless configuration, what are you going to do, code in the offset to your business logic?

By default Spludlow Printing will get the printable area and apply an offset to everything you draw with the correct page origin.

.net Printing allows you to get the printable area (which ultimately gets it from the printer driver) and then you can apply the offset to the underlying Graphics printing object using the TranslateTransform() method.

So normally you have nothing to worry about when it comes to the printable area just don’t draw anything outside it if you are ever planning for you page to get printed out.

Alignment Problems

The problem comes when printing to labels or pre-printed forms and you notice it’s out by a few millimetres so the page is “out of register”.

For whatever reason the automatically acquired printable area is not quiet what it you are seeing in reality.

Fixing Alignment Problems with Configuration

Spludlow Printing allows you to override the default printable area when you are out of register using configuration.

There are 3 levels of overrides:

·         Printer

·         Printer, Orientation

·         Printer, Orientation, Tray

Define them from the top and add further down configurations as you need them. You may find the printer only configuration works fine until you print something landscape so then add the printer-landscape configuration.

Perform the following steps (The example printer is called “Canon L120”):

·         Run the method “Spludlow.Printing.PrinterSetting.MakePrintableAreaConfigTemplate()” on the Internet call page.

·         Look on the Intranet Logs page for the “MakePrintableAreaConfigTemplate” Report, click on it

·         Copy and paste the result into notepad. This template contains all combinations of all printers you may need, you won’t need them all!

·         Look for the printer only line for example “<add key="Spludlow.PrintMargin.Canon L120" value="0, 0" />”

·         Copy and paste this line into the Spludlow Configuration Internet Page at the network level. Then release the configuration to the hosts

·         Print a grey square at 0, 0 with a size of 30mm. (See code below)

·         Note the square is offset, measure these offsets with a ruler, this is the real offset. (When you print with 0,0 configured a warning will be logged that says what the default would have been)

·         Edit the configuration with the measured offset values and release configuration.

·         Print the square again, now the square should have the top and left chopped off but the edge of the paper should measure 30mm to the other side of the square, we are in alignment.

Code to draw the square and print it:

       Spludlow.Printing.PrintDoc printDoc = new Spludlow.Printing.PrintDoc("A4", "Portrait Test");

       Spludlow.Printing.PrintDoc printDoc = new Spludlow.Printing.PrintDoc("A4*", "Landscape Test");

 

       printDoc.Rectangle(0, 0, 30, 30, 1.0F, Color.Black, Color.LightGray);

       Spludlow.Printing.Printer.Print(printDoc, "system: canon");

Unless you printer has uniform margins or you only print portrait then you will also need to setup a configuration line for the landscape as well for example both line where added:

<add key="Spludlow.PrintMargin.Canon L120.P" value="4, 5" />

<add key="Spludlow.PrintMargin.Canon L120.L" value="5, 4" />

 

Example of some tray specific configuration.

                <add key="Spludlow.PrintMargin.Phaser 7760 PS.P.Tray 3" value="5, 4" />

                <add key="Spludlow.PrintMargin.Phaser 7760 PS.L.Tray 3" value="6, 5" />

 

Remember to release configuration after making changes.

Several factors can affect the page registration like; tolerances in the hardware (each page may just simply jiggle around a bit), tolerances in the paper, paper size, paper tray used, and the way the tray is loaded.

You may find after configuring you are still slightly out, so let it run in the real world and measure a few sheets taking the average so you can finely tweak the offset.

The offsets are positive numbers. Lowering the offset numbers moves things closer to the edge of the page and increasing moves things into the page.

The offset is in millimetres and you can use decimals, for example values like “3.5, 5.25” could be used when taking averages.


 
 
 
 
 
 
 
 
 
Spludlow Web Footer