Link
Skip to main content

Print PDF Files in Java

JPedal is a pure Java PDF library that gives Java developers the ability to print PDF files programmatically — from the command line or embedded directly in a Java application. For more advanced control over paper size, page scaling, and printer selection, see the 5 step printing tutorial.

# Print page 1 of a document
java -jar jpedal.jar --print "inputFile.pdf" PRINTER_NAME 1
# Print the whole document
java -jar jpedal.jar --print "inputFile.pdf" PRINTER_NAME

The command line interface can be invoked from any language that supports child processes, including Python, Node.js, C#, and shell scripts.

PrintPdfPages print = new PrintPdfPages("inputFile.pdf");
if (print.openPDFFile()) {
    print.printAllPages("Printer Name");
    // or print a single page:
    // print.printPage("Printer Name", pageNumber);
}

View the full Java source code for this example, including additional printing features.

Frequently Asked Questions

How do I print a PDF in Java?

Use the PrintPdfPages class to open the file with openPDFFile(), then call printAllPages() with the printer name. For advanced options including page scaling, paper size, and page ranges, see the 5 step printing tutorial.

How do I find the printer name to pass to JPedal?

Use the standard Java Print Service API: PrintServiceLookup.lookupPrintServices() returns all printers available to the JVM. Pass the printer’s getName() value to JPedal’s print methods.

Can JPedal print a single page rather than the whole document?

Yes. Use print.printPage("Printer Name", pageNumber) where page numbering starts at 1.

Can JPedal print password-protected PDF files?

Yes. Set the password before opening the file. See the 5 step printing tutorial for the encrypted file API.

Can I print a PDF without writing Java code?

Yes. JPedal’s command line interface supports printing directly: java -jar jpedal.jar --print "inputFile.pdf" PRINTER_NAME. This also allows invocation from Python, Node.js, C#, shell scripts, or any language that supports child processes.

Does JPedal support server-side PDF printing?

Yes. JPedal supports silent server-side printing without a display. Ensure the JVM is configured for headless mode where required.

Does JPedal require any third-party libraries for printing?

No. JPedal has no required third-party Java dependencies. There are no native binaries and no external print drivers required beyond what the host operating system provides.

What Java version is required?

JPedal requires Java 17 as a minimum. Details at Which Java versions does JPedal support?


Why JPedal?

  • Actively developed commercial library with full support and no third party dependencies.
  • Process PDF files up to 3x faster than alternative Java PDF libraries.
  • Simple licensing options and source code access for OEM users.

Learn more about JPedal

Start Your Free Trial


Customer Downloads

Select Download