Python 를 통해 PDF 문서의 북마크로 작업하기

Python 를 사용하여 프로그래밍 방식으로 PDF의 북마크를 조작하는 방법.

Python 라이브러리를 사용하여 PDF 문서에서 북마크를 사용하는 방법

PDF 파일에 북마크를 추가하기 위해 python-net 플랫폼을 위한 기능이 풍부하고 강력하며 사용하기 쉬운 문서 조작 API인 Aspose.PDF for .NET API를 사용할 것입니다.NuGet 패키지 관리자를 열고 Aspose.pdf를 검색하여 설치합니다.패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.

Python Package Manager Console

pip install aspose-pdf

Python 를 통한 북마크 작업 단계


사용자 환경에서 코드를 테스트하려면 Aspose.PDF for .NET 이 필요합니다.

1.문서 객체를 사용하여 PDF 문서를 엽니다. 1.북마크를 생성하고 북마크의 속성을 정의합니다. 1.아웃라인 항목 컬렉션 컬렉션을 아웃라인 컬렉션에 추가합니다. 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)