Drukowanie PDF przez Python

Jak wydrukować plik PDF przy użyciu biblioteki Python

Jak wydrukować plik PDF za pomocą biblioteki Python

Aby wydrukować plik PDF, użyjemy interfejsu API Aspose.PDF for .NET, który jest bogatym w funkcje, wydajnym i łatwym w użyciu interfejsem API do manipulacji dokumentami dla platformy python-net. Otwórz menedżera pakietów NuGet, wyszukaj Aspose.pdf i zainstaluj. Można również użyć następującego polecenia z konsoli Menedżera pakietów.

Python Package Manager Console

pip install aspose-pdf

Drukowanie dokumentu PDF poprzez Python


Potrzebujesz Aspose.PDF for .NET, aby wypróbować kod w swoim środowisku.

  1. Załaduj plik PDF z wystąpieniem dokumentu.
  2. Pobierz DocumentInfo za pomocą właściwości Document.info.
  3. Dostęp i wyświetlanie różnych właściwości Document.info.

Drukuj PDF - Python

<% print.code-block.subtitle %>

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