GroupDocs.Redaction for Java 20.11 Release Notes

Major Features

There are the following improvements in this release:

  • Ability to save Redaction Policy to an XML file
  • Built-in support for plain text format (previously was an example)
  • Support for HTML documents and Markdown files
  • Improve PDF preview generation

Full List of Issues Covering all Changes in this Release

KeySummaryCategory
REDACTIONJAVA-107Saving RedactionPolicy.xml fileImprovement
REDACTIONJAVA-108Add support for HTML documents and Markdown filesImprovement
REDACTIONJAVA-109Add built-in support for plain text formatImprovement
REDACTIONJAVA-110Improve PDF preview generationImprovement

Public API and Backward Incompatible Changes

Saving RedactionPolicy.xml file in Java

This feature provides functionality to save a redaction policy created in code as an XML file for further use.

Add support for HTML documents and Markdown files

This feature provides support for HTML documents and Markdown files.

Add built-in support for plain text format

This feature provides built-in support for plain text format. Previously, user had to take the class from public examples and configure it as a custom format handler.

Improve PDF preview generation

This feature contains improvements for PDF preview rendering and embedded images redactions.

Public API changes

Constructor RedactionPolicy(Redaction[]) taking an array of redactions has been added.
Methods RedactionPolicy.save(String) and RedactionPolicy.save(OutputStream) have been added.
Class Redactor now implements interface IPreviewable.

Usage

The following example demonstrates how to save a RedactionPolicy to an XML file.

RedactionPolicy policy = new RedactionPolicy(new Redaction[] {
    new ExactPhraseRedaction("Redaction", new ReplacementOptions("[Product]")),
    new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions(java.awt.Color.BLUE)),
    new DeleteAnnotationRedaction(),
    new EraseMetadataRedaction(MetadataFilters.All)
});
policy.save("MyPolicyFile.xml");

The following example demonstrates how to get a single page preview of the document.

// Test file
final String testFile = "D:\\sample.pdf";
// Take preview of the first page
int testPageNumber = 1;
// Preview file name
final String previewFileName = String.format("%s_page%d.png", testFile, testPageNumber);
// Load the document to generate preview
final Redactor redactor = new Redactor(testFile);
try 
{
    PreviewOptions options = new PreviewOptions(new ICreatePageStream() { 
        @Override
        public java.io.OutputStream createPageStream(int pageNumber) { 
            try {
                return new java.io.FileOutputStream(previewFileName); 
            } catch (java.io.FileNotFoundException ex) {
                System.out.printf("Failed to create preview file %s: \"%s\"\n\n", previewFileName, ex.toString());
                return null;
            }
        } 
    });
    options.setHeight(640);
    options.setWidth(480);
    options.setPageNumbers(new int[] { testPageNumber });
    options.setPreviewFormat(PreviewFormats.Png);
    redactor.generatePreview(options);            
    System.out.printf("\nPreview for page: %d  was saved to \"%s\"\n\n", testPageNumber, previewFileName);
}
finally { redactor.close(); }