PDF リダクション

無料のクロスプラットフォームアプリと API で PDF ドキュメント内のコンテンツを検索して削除する

PDF ファイルを編集する方法

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

PDF ドキュメントを編集


ご使用の環境でコードを試すには、Aspose.PDF ライブラリ が必要です。

1。PDF に Document のインスタンスをロードします。 1。検索語を引数として TextFragmentAbSorber オブジェクトを作成します。 1。検索オプションを設定します。 1。各フラグメントコレクションをループ処理して編集します。 1。PDF ファイルを保存します。

PDF を編集-C#


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

    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchTerm);
    TextSearchOptions textSearchOptions = new TextSearchOptions(true);
    textFragmentAbsorber.TextSearchOptions = textSearchOptions;

    doc.Pages.Accept(textFragmentAbsorber);
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
    foreach (TextFragment textFragment in textFragmentCollection)
{
    Page page = textFragment.Page;
    Rectangle annotationRectangle = textFragment.Rectangle;

    Annotations.RedactionAnnotation annot = new Annotations.RedactionAnnotation(page, annotationRectangle);
    annot.FillColor = Color.Black;
    doc.Pages[textFragment.Page.Number].Annotations.Add(annot, true);
    annot.Redact();
}
    doc.Save(dataDir + "output.pdf");