Redactar formatos PDF en C#

Información de redacción confidencial de documentos PDF nativos y de alto rendimiento mediante el uso de Aspose.PDF del lado del servidor para las API C#, sin el uso de ningún software como Microsoft o Adobe PDF.

Cómo redactar un archivo PDF con la biblioteca C#

Para redactar el archivo PDF, usaremos la API Aspose.PDF for .NET, que es una API de manipulación de documentos rica en funciones, potente y fácil de usar para la plataforma net. Abra el administrador de paquetes NuGet, busque Aspose.pdf e instálelo. También puede usar el siguiente comando desde la consola de Package Manager.

Redactar documentos PDF a través de C#


Necesita Aspose.PDF for .NET para probar el código en su entorno.

  1. Cargue el PDF con una instancia de Document.
  2. Cree un objeto TextFragmentAbsorber con términos de búsqueda como argumento
  3. Defina las opciones de búsqueda.
  4. Recorra cada recopilación de fragmentos para redactar.
  5. Guarde el archivo PDF.

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