redactionOptions Property

Summary

Redaction options to use when this document is viewed or converted.

Syntax
TypeScript
JavaScript
Object.defineProperty(DocumentAnnotations.prototype, 'redactionOptions', 
   get: function(), 
   set: function(value) 
) 
redactionOptions: DocumentRedactionOptions; 

Property Value

The redaction options to use when this document is viewed or converted. The default value is null.

Remarks

The default value of null instructs the DocumentViewer and DocumentConverter to not perform any special processing for the annotations objects in the pages of this LEADDocument during viewing or converting.

To apply the annotations, set a new instance of DocumentRedactionOptions in RedactionOptions and modify its options for the desired operations.

For more information, refer to Document View and Convert Redaction.

Example

This example will load a PDF document, then dynamically apply redactions to any word containing "leadtools" found and save it back into an external PDF

TypeScript
JavaScript
const url = "http://demo.leadtools.com/images/pdf/leadtools.pdf"; 
const loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
 
log("Loading document..."); 
lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
   .done((document) => { 
      document.isReadOnly = false; 
      const toRedact = "leadtools"; 
      const documentPage = document.pages.item(0); 
      documentPage.getText(lt.LeadRectD.empty) 
         .done((pageText) => { 
            log("Page Text retrieved"); 
            documentPage.getAnnotations(true) 
               .done((container) => { 
                  log("Annotations retrieved"); 
                  pageText.buildWords(); 
                  log("Redacting all instances of: " + toRedact); 
                  pageText.words.forEach((word) => { 
                     if (word.value.indexOf(toRedact) !== -1) { 
                        const annRedactObject = new lt.Annotations.Engine.AnnRedactionObject(); 
                        annRedactObject.rect = word.bounds; 
                        container.children.add(annRedactObject); 
                     } 
                  }); 
 
                  documentPage.setAnnotations(container) 
                     .done(() => { 
                        log("Annotations set."); 
                        document.annotations.redactionOptions = new lt.Document.DocumentRedactionOptions(); 
                        document.annotations.redactionOptions.viewOptions.mode = lt.Document.DocumentRedactionMode.apply; 
                        document.annotations.redactionOptions.viewOptions.replaceCharacter = '*'; 
                        document.annotations.redactionOptions.convertOptions.mode = lt.Document.DocumentRedactionMode.apply; 
                        document.annotations.redactionOptions.convertOptions.replaceCharacter = '*'; 
                        document.isReadOnly = true; 
 
                        log("Convert to pdf."); 
                        const jobData = new lt.Document.DocumentConverterJobData(); 
                        jobData.documentFormat = lt.Document.Writer.DocumentFormat.pdf; 
                        jobData.rasterImageFormat = lt.Document.RasterImageFormat.unknown; 
                        document.convert(jobData) 
                           .done((result) => { 
                              // This is generic code-- this code checks if the results have been archived into a ZIP file if this 
                              // example was converting to, say SVG 
                              const resultDocument = result.document != null ? result.document.url : result.archive.url; 
                              const link = window.document.createElement("a"); 
                              const url = lt.Document.DocumentFactory.serviceUri + "/" + resultDocument; 
                              link.href = url; 
                              link.innerHTML = url; 
                              link.target = "_default"; 
                              log("Converted: " + url, url); 
                           }) 
                     }) 
                     .fail(showServiceError); 
               }) 
               .fail(showServiceError); 
         }) 
         .fail(showServiceError); 
   }) 
   .fail(showServiceError); 
class DocumentAnnotations_RedactionOptionsExample { 
    public constructor() { 
        lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt", "EVAL", null); 
    } 
 
    public run(buttonID: string) { 
        document.getElementById(buttonID).onclick = this.convertRedact; 
    } 
 
    convertRedact = () => { 
        const url = "http://demo.leadtools.com/images/pdf/leadtools.pdf"; 
        const loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
 
        log("Loading document..."); 
        lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
            .done((document: lt.Document.LEADDocument) => { 
                document.isReadOnly = false; 
                const toRedact = "leadtools"; 
                const documentPage = document.pages.item(0); 
                documentPage.getText(lt.LeadRectD.empty) 
                    .done((pageText: lt.Document.DocumentPageText)=>{ 
                        log("Page Text retrieved"); 
                        documentPage.getAnnotations(true) 
                            .done((container) =>{ 
                                log("Annotations retrieved"); 
                                pageText.buildWords(); 
                                log("Redacting all instances of: " + toRedact); 
                                pageText.words.forEach((word) => { 
                                    if(word.value.indexOf(toRedact) !== -1){ 
                                        const annRedactObject = new lt.Annotations.Engine.AnnRedactionObject(); 
                                        annRedactObject.rect = word.bounds; 
                                        container.children.add(annRedactObject); 
                                    } 
                                }); 
 
                                documentPage.setAnnotations(container) 
                                    .done(() => { 
                                        log("Annotations set."); 
                                        document.annotations.redactionOptions = new lt.Document.DocumentRedactionOptions(); 
                                        document.annotations.redactionOptions.viewOptions.mode = lt.Document.DocumentRedactionMode.apply; 
                                        document.annotations.redactionOptions.viewOptions.replaceCharacter = '*'; 
                                        document.annotations.redactionOptions.convertOptions.mode = lt.Document.DocumentRedactionMode.apply; 
                                        document.annotations.redactionOptions.convertOptions.replaceCharacter = '*'; 
                                        document.isReadOnly = true; 
 
                                        log("Convert to pdf."); 
                                        const jobData = new lt.Document.DocumentConverterJobData(); 
                                        jobData.documentFormat = lt.Document.Writer.DocumentFormat.pdf; 
                                        jobData.rasterImageFormat = lt.Document.RasterImageFormat.unknown; 
                                        document.convert(jobData) 
                                            .done((result: any) => { 
                                                // This is generic code-- this code checks if the results have been archived into a ZIP file if this 
                                                // example was converting to, say SVG 
                                                const resultDocument = result.document != null ? result.document.url : result.archive.url; 
                                                const link = window.document.createElement("a"); 
                                                const url = lt.Document.DocumentFactory.serviceUri + "/" + resultDocument; 
                                                link.href = url; 
                                                link.innerHTML = url; 
                                                link.target = "_default"; 
                                                log("Converted: " + url, url); 
                                            }) 
                                    }) 
                                    .fail(showServiceError); 
                            }) 
                            .fail(showServiceError); 
                    }) 
                    .fail(showServiceError); 
 
 
            }) 
            .fail(showServiceError); 
    } 
} 

Requirements

Target Platforms

Help Version 20.0.2019.4.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly