Q:
Is there a way to add text onto a PDF page within WebViewer?
A:
Yes, WebViewer’s Stamper API enables you to add text to a particular area on a PDF page:
WebViewer({
fullAPI: true,
// other constructor options
}, viewerElement).then(instance => {
const { docViewer, PDFNet } = instance;
await PDFNet.initialize();
const doc = await docViewer.getDocument().getPDFDoc();
const s = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
s.setAsAnnotation(false);
s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
s.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_center, PDFNet.Stamper.VerticalAlignment.e_vertical_top);
const font = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_courier);
s.setFont(font);
const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
s.setFontColor(redColorPt);
s.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
s.setAsBackground(true);
const pgSet = await PDFNet.PageSet.createRange(1, 2);
s.stampText(doc, 'This is a title!', pgSet);
})