PDF 文件密文解決方案

使用免費的跨平臺應用程式和 API 查找和刪除 PDF 文件中的內容

如何編輯 PDF 檔

為了編輯PDF文件,我們將使用[Aspose.PDF](https://products.aspose.com/pdf)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於任何平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

密文文檔


您需要 [Aspose.PDF 庫](https://releases.aspose.com/pdf) 來嘗試環境中的代碼。

  1. 載入包含文件實例的 PDF。 創建文本碎片以搜索詞作為參數的吸收物件。
  2. 設定搜尋選項。
  3. 迴圈遍歷每個片段收集以進行密文。
  4. 儲存檔。

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