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

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

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

เพื่อที่จะดึงสิ่งที่แนบมาในไฟล์ 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 .NET เพื่อลองรหัสในสภาพแวดล้อมของคุณ

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

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

 def attachment_extract(self, infile):

        path_infile = self.dataDir + infile

        # Open document
        pdfDocument = Document(path_infile)

        # Get embedded files collection
        embeddedFiles = pdfDocument.EmbeddedFiles

        # Get count of the embedded files
        print ( "Total files : %d " % (embeddedFiles.Count))

        count = 1

        # Loop through the collection to get all the attachments

        for fileSpecification in embeddedFiles:
            print("Name: " + fileSpecification.Name)
            print("Description: " + fileSpecification.Description)
            print("Mime Type: " + fileSpecification.MIMEType)

            # Check if parameter object contains the parameters
            if (fileSpecification.Params != None):
                print("CheckSum: " + fileSpecification.Params.CheckSum)
                print("Creation Date: " + fileSpecification.Params.CreationDate)
                print("Modification Date " + fileSpecification.Params.ModDate)
                print("Size: " + fileSpecification.Params.Size)

                # Get the attachment and write to file or stream
                File.WriteAllBytes(self.dataDir + count + "_out" + ".txt", fileSpecification.Contents)

                count+=1