[]
        
(Showing Draft Content)

Text Markup Annotation

Text markup annotations are used to mark up text in a document. They can appear as highlights, underlines, strikeouts, or squiggly underlines applied to the page text. The type of markup is specified using the markupType property.

Text-Markup-Annotation.png

Use the TextMarkupAnnotation class to add text markup annotations to a PDF document.

const doc = new PdfDocument();
const page = doc.newPage();

let rc = { x: 50, y: 50, width: 200, height: 50 };
const layout = new Layout({
    runs: [{
        text: "This sample demonstrates how you can create Text markup annotation.",
        font: Font.getPdfFont(StandardPdfFont.Times),
        fontSize: 11
    }],
    maxWidth: rc.width,
    maxHeight: rc.height
});
page.context.drawLayout(layout, rc.x, rc.y);
rc = Util.inflate(rc, 15, 24)

//Create an instance of CircleAnnotation class and set its relevant properties
var textMarkupAnnot = new TextMarkupAnnotation();
textMarkupAnnot.markupType = TextMarkupType.Highlight;
textMarkupAnnot.userName = "Jaime Smith";
textMarkupAnnot.contents = "This is a Text markup annotation";
//search the text(e.g employee name) which needs to be redacted
const found = doc.findText({ text: "Text markup", matchCase: true, wholeWord: false });
textMarkupAnnot.area = [].concat(...found.map((fp) => fp.bounds));
textMarkupAnnot.color = "Yellow";
page.annotations.add(textMarkupAnnot);

const docData = doc.savePdf();
Util.saveFile("TextMarkupAnnotation.pdf", docData);