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

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

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

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

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


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

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");