Stampa il PDF tramite Python

Stampa documenti PDF. Utilizza Aspose.PDF per Python for .NET per modificare i file PDF a livello di codice

Come stampare PDF usando la libreria Python

Per stampare un file PDF, utilizza Aspose.PDF for Python via .NET, un’API potente e facile da usare. Apri PyPI, cerca aspose-pdf e installalo. In alternativa, esegui il comando:

Console

pip install aspose-pdf

Stampa di documenti PDF tramite Python


Per provare il codice nel tuo ambiente, ti serve Aspose.PDF for Python via .NET.

  1. Carica il PDF con un’istanza di Document.
  2. Ottenere DocumentInfo utilizzando la proprietà Document.
  3. Accedere e visualizzare diverse proprietà Document.Info.

Stampa PDF - Python

Questo codice di esempio mostra come stampare un file PDF

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()