แยกไฟล์แนบจาก PDF ผ่าน Python

วิธีการแยกไฟล์แนบจาก PDF โดยทางโปรแกรมด้วย Python

วิธีการแยกสิ่งที่แนบมาโดยใช้ Python for .NET ห้องสมุด

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

Console

pip install aspose-pdf

สารสกัดจากเอกสารแนบจาก PDF Python


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

1.รับคอลเลกชันไฟล์ที่ฝังตัว 1.ได้รับการนับของไฟล์ที่ฝังตัว 1.ห่วงผ่านคอลเลกชันที่จะได้รับสิ่งที่แนบมาทั้งหมด 1.ตรวจสอบว่าวัตถุพารามิเตอร์มีพารามิเตอร์ 1.รับสิ่งที่แนบมาและเขียนไปยังแฟ้มหรือสตรีม

สารสกัดจากเอกสารแนบ PDF

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
# Open document
document = apdf.Document(path_infile)

# Get count of the embedded files
print(f"Total files : {len(document.embedded_files)}")

# Loop through the collection to get all the attachments
for file_specification in document.embedded_files:
    print(f"Name: {file_specification.name}")
    print(f"Description: {file_specification.description}")
    print(f"Mime Type: {file_specification.mime_type}")

    # Check if parameter object contains the parameters
    if file_specification.params is not None:
        print(f"CheckSum: {file_specification.params.check_sum}")
        print(f"Creation Date: {file_specification.params.creation_date}")
        print(f"Modification Date: {file_specification.params.mod_date}")
        print(f"Size: {file_specification.params.size}")

    # Get the attachment and write to file
    with open(
        path.join(self.data_dir, "export_" + file_specification.name), "wb"
    ) as f:
        f.write(file_specification.contents.readall())