พิมพ์ PDF ผ่าน Python

พิมพ์เอกสาร PDFใช้ Aspose.PDF สำหรับ Python for .NET เพื่อแก้ไขไฟล์ PDF แบบโปรแกรม

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

หากต้องการพิมพ์ไฟล์ PDF ให้ใช้ Aspose.PDF for Python via .NET ซึ่งเป็น API ที่มีประสิทธิภาพและใช้งานง่าย เปิด PyPI ค้นหา aspose-pdf แล้วติดตั้ง หรือเรียกใช้คำสั่งต่อไปนี้:

Console

pip install aspose-pdf

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


หากต้องการลองใช้โค้ดในสภาพแวดล้อมของคุณ คุณต้องมี Aspose.PDF for Python via .NET

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

พิมพ์ PDF - Python

รหัสตัวอย่างนี้แสดงวิธีการพิมพ์ไฟล์ 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()