PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
The steps to redact PDFs are as follows:
Create Redaction Annotations: A user applies to redact annotations that specify the pieces or regions of content that should be removed. This step marks the regions where redaction changes will be applied. These redaction annotations can be set, moved, or deleted before applying redaction changes, without removing content from the document.
Apply Redaction Changes: After marking the areas for complete content removal, apply redaction changes. The content within the regions of the redaction annotations will be irreversibly deleted.
Through these two steps, you can thoroughly remove sensitive data from the document.
You can use the CPDFRedactAnnotation class to create redaction annotations. Utilize the SetQuardRects or SetRect methods to define the areas that should be covered by the redaction annotations.
In addition, the appearance of the ciphertext can be customized at this stage. Note that once redaction annotations have been applied, their appearance cannot be changed. This is because the redaction annotations will become non-editable, non-modifiable, static content instead of an interactive ciphertext annotation after it has been applied.
This sample shows how to create redaction annotations:
CPDFDocument document = CPDFDocument.InitWithFilePath("filePath");
CPDFPage page = document.PageAtIndex(0);
CPDFRedactAnnotation redact = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_REDACT) as CPDFRedactAnnotation;
redact.SetRect(new CRect(0, 50, 50, 0));
redact.SetOverlayText("REDACTED");
CTextAttribute textDa = new CTextAttribute();
textDa.FontName = "Helvetica";
textDa.FontSize = 12;
byte[] fontColor = { 255, 0, 0 };
textDa.FontColor = fontColor;
redact.SetTextDa(textDa);
redact.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_LEFT);
byte[] fillColor = { 255, 0, 0 };
redact.SetFillColor(fillColor);
byte[] outlineColor = { 0, 255, 0 };
redact.SetOutlineColor(outlineColor);
redact.UpdateAp();ComPDF PDF SDK ensures that if text, images, or vector graphics are included in the region marked by a redaction annotation, the corresponding image or path data in that portion will be completely removed and cannot be restored.
This sample shows how to apply redaction changes:
document.ApplyRedaction();Use the CPDFPage.ErasureRedaction method to directly erase all content within a specified rectangular area of a page, without first creating a redaction annotation and then applying it. This is a simplified redaction operation suitable for quickly erasing specified areas:
CPDFDocument document = CPDFDocument.InitWithFilePath("filePath");
CPDFPage page = document.PageAtIndex(0);
// Directly erase all content within the specified rectangular area
CRect rect = new CRect(0, 50, 100, 0);
bool success = page.ErasureRedaction(rect);
if (success)
{
// Erasure successful, save the document
document.WriteToFilePath("outputPath");
}Note: The
ErasureRedactionmethod will immediately and permanently delete the content within the specified area. This operation is irreversible. Unlike creating redaction annotations, this method does not leave visible redaction marks in the document.