How To Print PDF Files Using Python

How To Print PDF Files Using Python

Printing PDF files in Python is a common requirement in document automation workflows — invoices sent to printers on generation, shipping labels queued automatically, audit reports dispatched on schedule. IronPDF for Python provides two direct methods: pdf.Print() for immediate default-printer output and pdf.GetPrintDocument() for full control over page ranges, printer selection, copies, and collation.

This guide covers installation, loading PDFs, default printing, and custom print settings with working code examples for each.

Quickstart: Print a PDF File with Python

  1. Install IronPDF: pip install ironpdf
  2. Import the library: from ironpdf import *
  3. Load your PDF: pdf = PdfDocument.FromFile("MyPdf.pdf")
  4. Print with default settings: pdf.Print()
  5. Or configure settings first: printer_setting = pdf.GetPrintDocument()
from ironpdf import *

# Apply license key
License.LicenseKey = "YOUR-LICENSE-KEY"

# Load and print immediately
pdf = PdfDocument.FromFile("report.pdf")
pdf.Print()
from ironpdf import *

# Apply license key
License.LicenseKey = "YOUR-LICENSE-KEY"

# Load and print immediately
pdf = PdfDocument.FromFile("report.pdf")
pdf.Print()
PYTHON

What Is IronPDF and How Does It Help with PDF Printing?

IronPDF is a Python library that enables developers to generate, manipulate, and convert PDF documents. The library's printing support covers two patterns: direct default-printer output with a single method call, and document-level access to PrinterSettings for complete printer control.

With IronPDF, the underlying complexity of printer communication is handled by the library. Developers work with a high-level API instead of managing OS-level print spooler interactions, subprocess commands, or platform-specific print utilities. This means the same Python code works on Windows, Linux, and macOS without modification.

A key capability is the ability to convert HTML, CSS, and JavaScript into PDF before printing — useful when the source material is a web template or dynamic report rather than an existing file. For more on this, see the HTML to PDF tutorial. The library also supports merging PDFs before printing and compressing PDFs to reduce spool transfer time for large documents.

Why Choose IronPDF for Python PDF Printing?

IronPDF provides a complete printing API rather than relying on external tools like Ghostscript or Adobe Reader command-line flags. The library handles document rendering internally, which means print output matches on-screen appearance precisely. Cross-platform support, consistent PrinterSettings access, and no dependency on locally-installed PDF viewers are the primary practical advantages over subprocess-based approaches.

The library is also particularly useful when the content to print does not yet exist as a PDF. Developers can create a PDF from an HTML template, add headers and footers, apply a page layout with custom fonts, and then send the result directly to the printer — all within a single Python script. This makes IronPDF suitable for document-generation-to-print pipelines, not just for printing existing files.


How Do I Install IronPDF for Python?

The IronPDF package is available on PyPI and installs with a single pip command.

 pip install ironpdf

After installation, add the import statement at the top of your script:

from ironpdf import *
from ironpdf import *
PYTHON

IronPDF requires Python 3.6 or later. The package automatically downloads the IronPDF rendering engine on first use, so the initial import may take a moment. For environments with restricted outbound access, see the IronPDF Engine configuration guide for offline setup options.

Setting Your License Key

A license key is required for production use. Set it before any other IronPDF call:

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"
PYTHON

The library works in trial mode without a key for development and evaluation, but output PDFs will include a trial watermark. For troubleshooting installation issues, consult the installation troubleshooting guide.


How Do I Load a PDF File for Printing?

IronPDF Python PdfDocument.FromFile() loading a PDF from the filesystem into a PdfDocument object ready for printing

Loading a PDF from the filesystem into a PdfDocument object using IronPDF for Python.

IronPDF loads PDF files from the filesystem using PdfDocument.FromFile(). The method accepts a file path string and returns a PdfDocument object ready for printing, manipulation, or inspection.

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

# Load from a file path
pdf = PdfDocument.FromFile("MyPdf.pdf")

# Load from bytes (e.g., a file read from a database or HTTP response)
with open("MyPdf.pdf", "rb") as f:
    pdf_bytes = f.read()
pdf_from_bytes = PdfDocument.FromBytes(pdf_bytes)

# Load a password-protected PDF
protected_pdf = PdfDocument.FromFile("SecurePdf.pdf", "password123")
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

# Load from a file path
pdf = PdfDocument.FromFile("MyPdf.pdf")

# Load from bytes (e.g., a file read from a database or HTTP response)
with open("MyPdf.pdf", "rb") as f:
    pdf_bytes = f.read()
pdf_from_bytes = PdfDocument.FromBytes(pdf_bytes)

# Load a password-protected PDF
protected_pdf = PdfDocument.FromFile("SecurePdf.pdf", "password123")
PYTHON

The code above demonstrates three loading patterns. FromFile() is the most common for file-system workflows. FromBytes() is useful when the PDF arrives as binary data from a database query or API response. The optional password parameter in FromFile() handles encrypted PDFs without any additional decryption step.

For PDFs sourced from a URL or HTML content, IronPDF can also convert a URL to PDF or render an HTML file to PDF before printing.

Supported Input Sources

Beyond PDF files, IronPDF can produce printable documents from images, HTML strings, and live URLs. This is useful in print workflows where the source data is not already a PDF — for example, rendering a report template with charts to PDF first, then sending to the printer.


How Do I Print a PDF Using Default Settings?

Python script calling pdf.Print() with the resulting print job visible in the Windows print queue

A Python script using IronPDF's `Print()` method sends a PDF job to the system default printer.

The Print() method sends the document to the system's default printer using default page settings. No additional configuration is needed.

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

# Load the PDF
pdf = PdfDocument.FromFile("invoice.pdf")

# Print to default printer with default settings
pdf.Print()
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

# Load the PDF
pdf = PdfDocument.FromFile("invoice.pdf")

# Print to default printer with default settings
pdf.Print()
PYTHON

Default settings use the system's configured default printer, print all pages, apply the printer's own default paper size and orientation, and send one copy. This is the right choice for simple workflows where the user's printer configuration already matches the document requirements.

For production code, wrap the print call in error handling to catch printer-offline or permission errors:

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

try:
    pdf = PdfDocument.FromFile("invoice.pdf")
    pdf.Print()
except Exception as e:
    print(f"Print job failed: {e}")
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

try:
    pdf = PdfDocument.FromFile("invoice.pdf")
    pdf.Print()
except Exception as e:
    print(f"Print job failed: {e}")
PYTHON

The exception message provides OS-level detail about the print failure — for example, whether the printer is offline, the spooler is paused, or the document failed to render.


How Do I Customize Print Settings Before Printing?

IronPDF Python GetPrintDocument() showing PrinterSettings properties including PrinterName, FromPage, ToPage, and Copies set in a Python script

IronPDF's `GetPrintDocument()` method returns a PrintDocument object with full access to PrinterSettings properties.

GetPrintDocument() returns a PrintDocument object that exposes the full PrinterSettings API. This allows selecting a named printer, setting page ranges, controlling copies and collation, and configuring duplex mode before sending the job.

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

pdf = PdfDocument.FromFile("quarterly-report.pdf")

# Access the PrintDocument object
printer_setting = pdf.GetPrintDocument()

# Select a specific printer by name
printer_setting.PrinterSettings.PrinterName = "HP LaserJet Pro"

# Print only pages 2 through 4
printer_setting.PrinterSettings.FromPage = 2
printer_setting.PrinterSettings.ToPage = 4

# Print 2 collated copies
printer_setting.PrinterSettings.Copies = 2
printer_setting.PrinterSettings.Collate = True

# Execute the print job
printer_setting.Print()
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

pdf = PdfDocument.FromFile("quarterly-report.pdf")

# Access the PrintDocument object
printer_setting = pdf.GetPrintDocument()

# Select a specific printer by name
printer_setting.PrinterSettings.PrinterName = "HP LaserJet Pro"

# Print only pages 2 through 4
printer_setting.PrinterSettings.FromPage = 2
printer_setting.PrinterSettings.ToPage = 4

# Print 2 collated copies
printer_setting.PrinterSettings.Copies = 2
printer_setting.PrinterSettings.Collate = True

# Execute the print job
printer_setting.Print()
PYTHON

The PrinterSettings.PrinterName property accepts the printer's display name as it appears in the OS printer list. On Windows, this matches the name shown in "Devices and Printers". On Linux, it corresponds to the CUPS printer name. Setting an invalid printer name will cause the print job to fail at runtime, so validate the name against the installed printer list when building user-facing print dialogs.

TipsTo list available printer names on Windows, use [System.Drawing.Printing.PrinterSettings]::InstalledPrinters in PowerShell, or use the Python win32print module from pywin32 to enumerate printers programmatically.

Selecting Pages and Managing Copies

The FromPage and ToPage properties define an inclusive page range. Page numbering starts at 1. Setting FromPage = 1 and ToPage = 0 (the default) prints all pages. The Copies property accepts an integer; combined with Collate = True, the printer assembles complete sets of the document before starting the next copy — the correct behavior for multi-page reports.

Batch Printing Multiple PDFs

For workflows that print a queue of documents, loop through the file list and call Print() for each:

from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

def batch_print(file_paths):
    for path in file_paths:
        try:
            pdf = PdfDocument.FromFile(path)
            pdf.Print()
        except Exception as e:
            print(f"Failed to print {path}: {e}")

batch_print(["invoice_001.pdf", "invoice_002.pdf", "shipping_label.pdf"])
from ironpdf import *

License.LicenseKey = "YOUR-LICENSE-KEY"

def batch_print(file_paths):
    for path in file_paths:
        try:
            pdf = PdfDocument.FromFile(path)
            pdf.Print()
        except Exception as e:
            print(f"Failed to print {path}: {e}")

batch_print(["invoice_001.pdf", "invoice_002.pdf", "shipping_label.pdf"])
PYTHON

For high-volume batch jobs, consider async printing to avoid blocking the main thread while each job spools.


What Are the Next Steps for Python PDF Printing?

This guide covered the two core printing patterns in IronPDF for Python: default-printer output with pdf.Print() and custom-settings output with pdf.GetPrintDocument(). Both approaches work on Windows, Linux, and macOS with no platform-specific code.

To extend these patterns in a production application, consider:

Start with a free trial license to test printing in your environment. Licensing options start from $999 for production deployment.

Download the full source code used in this guide.

Frequently Asked Questions

What is the quickest way to print a PDF file in Python?

The quickest way is IronPDF's Print() method. After installing with pip install ironpdf, load a PDF with PdfDocument.FromFile('yourfile.pdf') and call pdf.Print() to send it to the default printer immediately using default page settings.

How do I select a specific printer when printing PDFs in Python?

Use GetPrintDocument() to access the PrintDocument object, then set printer_setting.PrinterSettings.PrinterName to the display name of the target printer as it appears in your OS printer list. On Windows this matches the name in Devices and Printers; on Linux it is the CUPS printer name.

How do I print only specific pages of a PDF in Python?

Call pdf.GetPrintDocument() to get the PrintDocument object, then set printer_setting.PrinterSettings.FromPage and printer_setting.PrinterSettings.ToPage to the first and last page numbers (1-based). Call printer_setting.Print() to execute with those settings.

Does IronPDF for Python work on Linux and macOS?

Yes. IronPDF for Python works on Windows, Linux, and macOS. The same Python code runs without platform-specific modifications. On Linux, printer selection uses CUPS printer names. Installation requires Python 3.6 or later on all platforms.

Do I need a license key to use IronPDF's print features?

A license key is required for production use. Set it with License.LicenseKey = 'YOUR-LICENSE-KEY' before any other IronPDF call. During development the library runs without a key, but output documents will carry a trial watermark. A free trial license is available for evaluation.

How do I print multiple PDF files in a batch with Python?

Loop through a list of file paths, calling PdfDocument.FromFile(path) and pdf.Print() for each file. Wrap each iteration in a try-except block to catch per-file errors without stopping the entire batch. For high-volume jobs, consider async execution to avoid blocking the main thread.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Version: 2026.5 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast?
run a sample watch your HTML become a PDF.