Redigere i formati PDF in C#

Informazioni di redazione sensibili ai documenti PDF nativi e ad alte prestazioni utilizzando Aspose.PDF lato server per le API C#, senza l’uso di software come Microsoft o Adobe PDF.

Come redigere il file PDF usando la libreria C#

Per oscurare il file PDF, useremo l’API Aspose.PDF for .NET che è un’API di manipolazione dei documenti ricca di funzionalità, potente e facile da usare per la piattaforma net. Apri il gestore pacchetti NuGet, cerca Aspose.pdf e installa. È inoltre possibile utilizzare il seguente comando dalla console di Gestione pacchetti.

Redigere documenti PDF tramite C#


È necessario Aspose.PDF for .NET per provare il codice nel proprio ambiente.

  1. Carica il PDF con un’istanza di Document.
  2. Creare un oggetto TextFragmentAbsorber con i termini di ricerca come argomento.
  3. Imposta le opzioni di ricerca.
  4. Esegui un ciclo attraverso ogni frammento raccolto per oscurare.
  5. Salva il file PDF.

Redigere i file 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");