Adobe PDF Library

Printing a PDF File

To send a PDF file to a printer, use the code offered in the PrintPDF sample program.  This program is designed to prompt a user to enter the name of a PDF file to send to a printer, but you could automate the process to select PDF files.  For example, you could write code to select a series of PDF files from a server directory instead.

Open the file, and then select the print parameters:

PrintUserParams userParams = new PrintUserParams();
PrintParams printParams = userParams.PrintParams;

In Java, the parameter lines look like this:

// Get some parameters
PrintUserParams userParams = new PrintUserParams();
// These are the "other" print parameters that hang off the user parameters.
PrintParams printParams = userParams.getPrintParams();


Use pageRanges to print with specified page ranges, in C#:

IList<PageRange> pageRanges = new List<PageRange>();

pageRanges.Add(new PageRange(0, 1, PageSpec.AllPages));
pageRanges.Add(new PageRange(0, 1, PageSpec.EvenPagesOnly));
pageRanges.Add(new PageRange(0, 1, PageSpec.OddPagesOnly));
doc.printToFile(userParams, "");

Or in Java.  In this case, we show the lines commented out, as they appear in the original code:

// Printing with specified page ranges
// Uncomment next code to allow printing with specified page ranges

// List<PageRange> pageRanges = new ArrayList<PageRange>();

// pageRanges.add(new PageRange(0, 1, PageSpec.ALL_PAGES));
// pageRanges.add(new PageRange(0, 1, PageSpec.EVEN_PAGES_ONLY));
// pageRanges.add(new PageRange(0, 1, PageSpec.ODD_PAGES_ONLY));

// printParams.setPageRanges(pageRanges);

You can print to a Postscript file, and send that file to a printer separately, in C#:

doc.printToFile(userParams, "");

Or Java:

doc.printToFile(userParams, "");

Or you can select the default printer for a machine.  The versions in C# and Java are similar: