I have a PDF which uses commercial font 'UniversLTPro-45Light'. While modifying the PDF to add a new Phrase, the font gets changed. Is it possible to have the same font for the new Phrase?
Here's the code I tried based on ReuseFont example:
public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
BaseFont bf = findFontInForm(reader, new PdfName("UniversLTPro-45Light"));
PdfContentByte canvas = stamper.getOverContent(3);
Font f = new Font(bf, 11);
f.setColor(35,31,32);
Phrase phrase = new Phrase("Some text in UniversLTPro-45Light", f);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase, 36, 575, 0);
stamper.close();
}
The new text after the phrase 'help you better understand this important topic.' in the PDF appears slightly thicker as in the screenshot below: