Adobe PDF Library

Printing

You can use the Adobe PDF Library and the Java and .NET Interface to create your own programs that print PDF documents.  Your programs would communicate with the Print API in the APDFL core library, and you can use the code offered in the PrintPDF sample program as a model. We provide a list of print options below to manage a print job.

  • Shrink to Fit
  • Expand to Fit
  • Rotate and Center
  • Set Page Size
  • Page Range
  • Paper Width/Height

You can include in your custom programs settings for these options; your program would pass these print options as flags to the Print API. For example, you can include, with a print job, the range of pages to print. You could create a user interface to enter the values for the print options, or have a user enter them at a command prompt.

The Java and .NET Interface also provides two print functions:

  • Use Default Printer
  • Pose Print Dialog

A print function is a program that queries the operating system. You can direct the system to send a print job to the default system printer selected on the local machine, and select all of the default settings for that printer.  You can also direct the system to open the appropriate print dialog window so that a user can manually select the right printer to use and manually enter print settings.

Print Options

ShrinkToFit

Use this option to reduce the size of the page you want to print to match the printer’s page size.

If you have enabled the SetPageSize option, ShrinkToFit will not work. Also, if the page you seek to print is already smaller than the printer page size, the printer will ignore the ShrinkToFit option.

ExpandToFit

Use this option to stretch the size of the page you want to print to match the printer’s page size.

If you have enabled the SetPageSize option, ExpandToFit will not work. Also, if the page you seek to print is already larger than the printer page size, the printer will ignore the ExpandToFit option.

If you want to set up the print job to fit the page content automatically to the printer’s page size, enable both of the Fit options, ShrinkToFit and ExpandToFit.

Let’s start with two graphics that you would like to print.

DLE_Print1_bridge

Here they are in their default sizes:

DLE_Print2_bridge

And here they are shown with the size of the paper to print them on, outlined in black:

DLE_Print3_bridge

If we use ShrinkToFit, note that the image of the web page becomes smaller to fit in the page boundaries.  But the photo of the bridge does not change, because it is already small enough:

DLE_Print4_bridge

If we use ExpandToFit, this time the image of the web page remains the same size.  It is already larger than the available space, so it shouldn’t grow any larger. But the photo of the bridge expands to fill the available space on the page.

DLE_Print5_bridge

If you use both options together, ShrinkToFit and ExpandToFit , both images are adjusted. The image of the web page is reduced, and the photo of the bridge is made larger, both to fit in the space provided.

DLE_Print6_bridge

RotateAndCenter

If this feature is enabled (True) the option centers the content in the middle of the page and then rotates the image clockwise if rotating the image will allow it to occupy the page space more efficiently. That means that if the image fits the page better without being rotated, the RotateAndCenter option won’t rotate the image.  If the CenterCropBox feature is also enabled it won’t affect how the image is placed on the page.  If the CenterCropBox option is set and RotateAndCenter is not, CenterCropBox will center the content.

If you have enabled the SetPageSize option, RotateAndCenter will not work.

Suppose you have an image like this:

DLE_Print7_rotate

And you want to print it on standard A4 paper:

DLE_Print8_rotate

It will look like this if both the RotateAndCenter and CenterCropBox options are turned off (False):

DLE_Print8_rotate

This is what the image will look like if both RotateAndCenter and CenterCropBox are enabled (True):

DLE_Print9_rotate

It looks the same if we enable RotateAndCenter (True) but not CenterCropBox  (False). In this case the RotateAndCenter will center the image, so CenterCropBox is not needed:

DLE_Print9_rotate

Finally, in this example, RotateAndCenter is disabled (False) and CenterCropBox is turned on (True):

DLE_Print10_rotate

So in this case the CenterCropBox centers the image on the page, but the image isn’t rotated because the Rotate feature is turned off.

SetPageSize

Use this option to tell the printer to select the right kind of paper to use for the print job. If you select SetPageSize it allows the printer to choose the correct paper size automatically, by drawing paper from the appropriate tray. The printer selects the paper of the right size based on the size of the print content in the print job.

Suppose a user wants to print a document that uses paper of different sizes. The first page of the document is A4, and the second and third are A5. If you select SetPageSize the printer could choose A4 paper from tray one for the first page and A5 paper from tray two for pages two and three. If the printer does not have paper of the right size it will select paper from the default tray. Or with SetPageSize selected, if a user sent a print job to a printer using letter sized paper (8½ by 11 inches) and then a second job using legal paper (8½ by 14 inches) the printer would select letter-size paper from tray one for the first job and legal-sized from tray two for the second.

If you have enabled the SetPageSize option, ExpandTofit, ShrinkToFit, and RotateAndCenter will not work.

If you enable the SetPageSize option (True), each print job will be able to draw the right size of paper from the printer tray where that paper is stored.

DLE_Print11_printer1

If the paper size doesn’t match, the printer uses the default tray.

In this case, the system will not adjust the print content to match the size of the paper offered. Rather, the print job tells the printer exactly what size of paper to use for printing, and the print content appears on the page in its original form. You can’t stretch or reduce the size of an image, rotate it, or center it on the page.

If you turn off SetPageSize (False), everything prints on paper stored in the default paper tray.

DLE_Print12_printer2

In this case you can use the ExpandToFit, ShrinktoFit, or RotateAndCenter options if you like.

PageRange

Use this option to select a page range for printing.

The PrintPDF sample program demonstrates how to send a PDF file to a printer. This C# program has two settings, PrintUserParams and PrintParams.

PrintUserParams offers start and ending values for page numbers (StartPage and EndPage).

PrintParams offers the PageRange field. This makes PrintParams more flexible, because you can set the page range and the way the range will be printed. For example, you could include a range of 40 pages, but then also tell the printer to only print even pages or only print odd pages. PrintUserParams only allows you to select all of the pages to print between your starting page and ending page.

Also, the PageRange field in PrintParams has priority over the StartPage/EndPage fields in PrintUserParams. If you set a range of pages in PageRange the system will disregard any page numbers entered for StartPage/EndPage in PrintUserParams.

PaperWidth/Height

This option allows you to set the paper size in PostScript points. A point is 1/72 of an inch; points are used with inches and millimeters to describe paper sizes.

If you provide a paper width or height the printer will ignore these values if SetPageSize is enabled.

Print Functions

UseDefaultPrinter

Select the default printer for the system as the printer to use. Make sure that you call UseDefaultPrinter before you set any page ranges for PrintParams or PrintUserParams. If you select the default printer after setting printer parameters, the settings for that default printer will override any values you enter for those print parameters. So you might set up a print job to only print odd pages, but if you then select the default printer, the default printer will reset the value back to print all pages.

PosePrintDialog

This function displays the print dialog box specific to the system the user is working with.  From this window the user can choose any printer from the list of available system printers (local and network), and choose any options that printer supports.

Make sure your custom programs call PosePrintDialog before you set any fields in PrintParams or PrintUserParams. The print dialog (PosePrintDialog) selects the default values for the printer. This means that PosePrintDialog will override any print options already in place using PrintParams or PrintUserParams.  After the user opens the print dialog and selects print options there, however, the user can manually override values entered for both PrintParams and PrintUserParams. For example, the program could call PosePrintDialog to display the print dialog window, allowing the user to select a printer.  Then, it could provide a second user interface or command line prompt where the user could manually select a page number range using the print options provided with the Adobe PDF Library Java and .NET Interface.

In Windows, you can also select a printer by specifying the printer name, the name of the driver, and the printer port name.  If a user selects a printer this way all of the set options (using PrintParams or PrintUserParams) will be left unchanged.