Aspose.PDF FOSS for Python เป็นไลบรารีโอเพ่นซอร์สสำหรับสร้าง, อ่าน, แก้ไข, เรนเดอร์, และตรวจสอบความถูกต้องของเอกสาร PDF. สร้างขึ้นสำหรับ Python 3.11 และรุ่นต่อมา, มาพร้อมกับข้อมูลประเภท และสามารถรวมเข้ากับโครงการ Python ใดก็ได้ (ดูส่วนการติดตั้งด้านล่าง). โครงการอยู่ในระยะอัลฟา, ดังนั้น API และการครอบคลุมฟีเจอร์จะยังคงพัฒนาเรื่อย ๆ ก่อนการปล่อยเวอร์ชันเสถียรแรก.
Document class เป็นจุดเข้าใช้งานหลัก, เปิดเผย pages, form, outlines,
และ tagged_content สำหรับการแก้ไขเชิงโครงสร้างพร้อมกับการดำเนินการ encrypt, decrypt, merge,
optimize, และ flatten. ข้อความจะถูกเพิ่มด้วย Page.add_text() และดึงออก
หรือค้นหาด้วย PdfExtractor และ TextFragmentAbsorber, รวมถึงการแทนที่และการทำให้เป็นสีที่ซ่อนโดยใช้วลีและ
การแทนที่แบบ regex. หน้าเรนเดอร์เป็นภาพ PNG หรือ TIFF raster ผ่าน
Page.render() และ Page.save_as_image(). ฟิลด์ AcroForm แบบโต้ตอบถูกสร้างและ
เติมข้อมูลผ่าน Form และ Field, และเอกสารสามารถตรวจสอบหรือแปลงเพื่อให้สอดคล้องกับ
PDF/A และ PDF/UA ด้วย Document.validate_pdfa(), Document.convert_to_pdfa(),
และ Document.auto_tag().
Aspose.PDF FOSS for Python ได้รับการเผยแพร่ภายใต้ใบอนุญาต MIT โดยไม่มีค่าธรรมเนียมการรันไทม์หรือ
ข้อจำกัดการใช้งาน. แพ็กเกจหลักขึ้นอยู่เพียง cryptography และ asn1crypto,
พร้อมกับส่วนเสริมเพิ่มเติมสำหรับการสนับสนุนภาพแบบ Pillow, การถอดรหัส WOFF2 แบบ Brotli, และ
การจัดวางข้อความซับซ้อนแบบ HarfBuzz. สำหรับฟีเจอร์และการสนับสนุนระดับองค์กร, ดู
Aspose.PDF for Python — Enterprise Product.
DocumentPageCollection ที่แก้ไขได้ซึ่งเปิดเป็น document.pagesPage.add_text()Page.add_image()Page.draw_rectangle() และ Page.draw_line()PdfExtractor และ get_text()has_next_page_text() และ get_next_page_text()TextFragmentAbsorberDocument.replace_text()Document.redact_text() โดยอาจวาดแถบทับซ้อนเพิ่มเติมPage.render()Page.save_as_image()Document.save_page_as_image()dpi และคุณภาพขอบด้วย antialiasRasterizedPage ที่ส่งกลับDocument.formForm.add_text_field()Form.add_checkbox() และ Form.add_radio_group()Form.add_list_box() และ Form.add_combo_box()Field.value จากนั้นทำให้แบนด้วย Document.flatten()Document.encrypt() โดยใช้รหัสผ่านของผู้ใช้และเจ้าของDocument.change_passwords() และ Document.decrypt()PdfSignature.validate()PdfLoadLimits ที่กำหนดค่าได้ValidationResultDocument.validate_pdfa()Document.convert_to_pdfa()Document.validate_pdfua()Document.auto_tag()Document.tagged_contentสร้างเอกสาร PDF ใหม่และเพิ่มข้อความที่กำหนดตำแหน่งลงในหน้าในไม่กี่บรรทัด
git clone https://github.com/aspose-pdf-foss/Aspose-PDF-FOSS-for-Python.git
cd Aspose-PDF-FOSS-for-Python
pip install -e .from aspose_pdf import Document
with Document() as document:
page = document.pages.add()
page.add_text(
"Hello from Aspose.PDF FOSS!",
x=72,
y=720,
font_size=18,
)
document.save("hello.pdf")
โหลด PDF ที่มีอยู่แล้วและบันทึกหน้าที่หนึ่งเป็นภาพเรสเตอร์ที่สามารถกำหนด DPI ได้
from aspose_pdf import Document
with Document() as document:
document.load_from("input.pdf")
document.pages[0].save_as_image("page-1.png", dpi=144)
ผูกเอกสารและดึงข้อความทั้งหมดของแต่ละหน้ามาโดยใช้ extractor facade.
from aspose_pdf import PdfExtractor
with PdfExtractor() as extractor:
extractor.bind_pdf("input.pdf")
extractor.extract_text()
print(extractor.get_text())
ต่อไฟล์ PDF หลายไฟล์เข้าด้วยกันเป็นเอกสารผลลัพธ์ไฟล์เดียว.
from aspose_pdf import PdfFileEditor
with PdfFileEditor() as editor:
if not editor.concatenate(["part-1.pdf", "part-2.pdf"], "merged.pdf"):
raise RuntimeError(editor.last_exception)