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:
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 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 a redaction annotation:
CPDFDocument document = new CPDFDocument(context);
document.open(pdfPath);
CPDFPage pdfPage = document.pageAtIndex(0);
CPDFRedactAnnotation redactAnnotation = (CPDFRedactAnnotation) pdfPage.addAnnot(CPDFAnnotation.Type.REDACT);
RectF pageSize = pdfPage.getSize();
RectF insertRect = new RectF(0, 0, 100, 100);
//coordinate conversion
insertRect = pdfPage.convertRectToPage(false, pageSize.width(), pageSize.height(), insertRect);
redactAnnotation.setRect(insertRect);
CPDFTextAttribute textAttribute = new CPDFTextAttribute(
CPDFTextAttribute.FontNameHelper.obtainFontName(CPDFTextAttribute.FontNameHelper.FontType.Helvetica, false, false), 14, Color.YELLOW);
redactAnnotation.setTextDa(textAttribute);
redactAnnotation.setFillColor(Color.RED);
redactAnnotation.setOverLayText("REDACTED");
redactAnnotation.updateAp();
redactAnnotation.applyRedaction();val document = CPDFDocument(context())
document.open(pdfPath)
val pdfPage = document.pageAtIndex(0)
val redactAnnotation = pdfPage.addAnnot(CPDFAnnotation.Type.REDACT) as CPDFRedactAnnotation
val pageSize = pdfPage.size
redactAnnotation.rect = kotlin.run {
//coordinate conversion
pdfPage.convertRectToPage(false, pageSize.width(), pageSize.height(), RectF(0F, 0F, 100F, 100F))
}
val textAttribute = CPDFTextAttribute(
CPDFTextAttribute.FontNameHelper.obtainFontName(CPDFTextAttribute.FontNameHelper.FontType.Helvetica, false, false), 14F, Color.YELLOW)
redactAnnotation.textDa = textAttribute
redactAnnotation.fillColor = Color.RED
redactAnnotation.overLayText = "REDACTED"
redactAnnotation.updateAp()
redactAnnotation.applyRedaction()The ComPDF 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.applyRedactions();document.applyRedactions()