การพิมพ์ไฟล์ PDF ผ่าน Python

วิธีการพิมพ์ไฟล์ PDF โดยใช้ไลบรารี Python

วิธีการพิมพ์ไฟล์ PDF โดยใช้ Python ไลบรารี

เพื่อที่จะพิมพ์ไฟล์ PDF เราจะใช้ Aspose.PDF for .NET API ซึ่งเป็นคุณลักษณะที่อุดมไปด้วยที่มีประสิทธิภาพและง่ายต่อการใช้ API การจัดการเอกสาร python-net แพลตฟอร์มเปิดตัวจัดการแพคเกจ NuGet ค้นหาaspose.pdf และติดตั้งนอกจากนี้คุณยังอาจใช้คำสั่งต่อไปนี้จากคอนโซลการจัดการแพคเกจ

Python Package Manager Console

pip install aspose-pdf

พิมพ์เอกสาร PDF ผ่าน Python


คุณจำเป็นต้อง Aspose.PDF for Python ที่จะลองรหัสในสภาพแวดล้อมของคุณ

1.โหลดไฟล์ PDF ที่มีอินสแตนซ์ของเอกสาร 1.รับ DocumentInfo ใช้คุณสมบัติ Document.Info 1.การเข้าถึงและแสดงคุณสมบัติ Document.Info ที่แตกต่างกัน

พิมพ์ 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()