Print PDF using Python

Print PDF documents. Use Aspose.PDF for Python for .NET to modify PDF files programmatically

How to Print PDF Using Python Library

In order to print PDF file, use Aspose.PDF for Python via .NET, a powerful and easy-to-use API. Open PyPI, search for aspose-pdf, and install it. Alternatively, run the command:

Console

pip install aspose-pdf

Printing PDF document via Python


To try the code in your environment, you need Aspose.PDF for Python via .NET.

  1. Load the PDF with an instance of Document.
  2. Get DocumentInfo using Document.Info property.
  3. Access & display different Document.Info properties.

Print PDF - Python

This sample code shows how to print PDF File

import aspose.pdf as apdf

import aspose.pdf.facades as apfacades
import aspose.pydrawing as drawing
import aspose.pdf.printing as aprinting

from os import path

path_infile = path.join(self.data_dir, infile)

# Create PdfViewer object
viewer = apfacades.PdfViewer()
viewer.bind_pdf(path_infile)

viewer.auto_resize = True
viewer.auto_rotate = True
viewer.print_page_dialog = False

ps =  aprinting.PrinterSettings()
pgs = aprinting.PageSettings()

ps.printer_name = "Microsoft Print to PDF"

# Set PageSize (if required)
pgs.paper_size = aprinting.PaperSizes.A4

# Set PageMargins (if required)
pgs.margins = apdf.devices.Margins(0, 0, 0, 0)

# Print document using printer and page settings
viewer.print_document_with_settings(pgs, ps)

# Close the PDF file after printing
viewer.close()