ทำงานกับบุ๊กมาร์กในเอกสาร PDF ผ่าน Python

วิธีการจัดการที่คั่นหน้าใน PDF โดยทางโปรแกรมด้วย Python

วิธีการทำงานกับบุ๊กมาร์กในเอกสาร PDF ด้วยไลบรารี Python

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

Python Package Manager Console

pip install aspose-pdf

ขั้นตอนในการทำงานกับบุ๊กมาร์กผ่าน Python


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

1.เปิดเอกสาร PDF โดยใช้วัตถุเอกสาร 1.สร้างบุ๊กมาร์กและกำหนดคุณสมบัติของมัน 1.เพิ่มคอลเลกชัน OutlineItemCollection ไปยังคอลเลกชันเค้าร่าง 1.บันทึกแฟ้มอีกครั้ง

<% bookmarks.code-block.text %>

เพิ่มที่คั่นหน้าลงในเอกสาร PDF - Python

<% bookmarks.code-block.subtitle %>

    def bookmark_add(self, infile, outfile):

        path_infile = self.dataDir + infile
        path_outfile = self.dataDir + outfile

        # Open document
        pdfDocument = Document(path_infile)

        # Create a bookmark object
        pdfOutline = OutlineItemCollection(pdfDocument.Outlines)
        pdfOutline.Title = "Test Outline"
        pdfOutline.Italic = True
        pdfOutline.Bold = True
        # Set the destination page number
        pdfOutline.Action = GoToAction(pdfDocument.Pages[1])
        # Add bookmark in the document's outline collection.
        pdfDocument.Outlines.Add(pdfOutline)

        # Save new output
        pdfDocument.Save(path_outfile)