Python の PDF フォーマットを墨消し

Microsoft や Adobe PDF などのソフトウェアを使用せずに、サーバー側の Aspose.PDF for Python API を使用して、ネイティブで高性能な PDF ドキュメントの機密編集情報。

Python ライブラリを使ってPDFファイルを編集する方法

PDF ファイルを編集するために、python-net プラットフォーム用の機能豊富で強力で使いやすいドキュメント操作 API である Aspose.PDF for .NET API を使用します。NuGet パッケージマネージャーを開き、aspose.pdf を検索してインストールします。パッケージマネージャーコンソールから次のコマンドを使用することもできます。

Python 経由でPDFドキュメントを墨消し


お使いの環境でコードを試すには Aspose.PDF for .NET が必要です。

1.PDF を Document のインスタンスとともに読み込みます。 1.検索用語を引数として TextFragmentAbsorber オブジェクトを作成します。 1.[検索オプション] を設定します。 1.各フラグメントコレクションをループして編集します。 1.PDF ファイルを保存します。

PDFファイルを墨消し-Python。


    doc = new Document(dataDir + "test.pdf")

    textFragmentAbsorber = TextFragmentAbsorber(searchTerm)
    textSearchOptions = TextSearchOptions(True)
    textFragmentAbsorber.TextSearchOptions = textSearchOptions

    doc.Pages.Accept(textFragmentAbsorber)
    textFragmentCollection = textFragmentAbsorber.TextFragments
    for textFragment in textFragmentCollection:
        page = textFragment.Page
        annotationRectangle = textFragment.Rectangle
        RedactionAnnotation annot = Annotations.RedactionAnnotation(page, annotationRectangle)
        annot.FillColor = Color.Black
        doc.Pages[textFragment.Page.Number].Annotations.Add(annot, true)
        annot.Redact()

        doc.Save(dataDir + "output.pdf")