Imprima el PDF a través de Python

Imprima documentos PDF. Utilice Aspose.PDF para que Python for .NET modifique archivos PDF mediante programación

Cómo imprimir PDF con la biblioteca Python

Para imprimir un archivo PDF, utilizaremos la API Aspose.PDF for .NET, que es una API de manipulación de documentos rica en funciones, potente y fácil de usar para la plataforma python-net. Abra el administrador de paquetes NuGet, busque Aspose.pdf e instálelo. También puede usar el siguiente comando desde la consola del administrador de paquetes.

Python Package Manager Console

pip install aspose-pdf

Impresión de documentos PDF a través de Python


Necesita Aspose.PDF for .NET para probar el código en su entorno.

  1. Cargue el PDF con una instancia de Document.
  2. Obtenga DocumentInfo mediante la propiedad Document.Info.
  3. Acceder y mostrar diferentes propiedades de Document.Info.

Imprima el PDF - Python

Este código de ejemplo muestra cómo imprimir un archivo PDF

import aspose.pdf as ap
import aspose.pydrawing as drawing

# Create PdfViewer object
viewer = ap.facades.PdfViewer()

# Open input PDF file
viewer.bind_pdf("input.pdf")

# Set attributes for printing
# Print the file with adjusted size
viewer.auto_resize = True
# Print the file with adjusted rotation
viewer.auto_rotate = True
# Do not produce the page number dialog when printing
viewer.print_page_dialog = False

# Create objects for printer and page settings
ps = drawing.printing.PrinterSettings()
pgs = drawing.printing.PageSettings()

# Set XPS/PDF printer name
ps.printer_name = "Microsoft XPS Document Writer"
# Or set the PDF printer
# ps.printer_name = "Adobe PDF"

# Set PageSize(if required)
pgs.paper_size = drawing.printing.PaperSize("A4", 827, 1169)

# Set PageMargins(if required)
pgs.margins = drawing.printing.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()