0

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:

screenshot

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
Emerald
  • 11
  • 5
  • Yes, usually that's possible, as long as you don't use characters that aren't in the font subset that is stored in your PDF. There are many things that can go wrong though. It's always better to have the font program at hand and to use that font program. There may also be legal implications. Since it's a commercial font: are you sure you can legally use it to update the PDF? – Bruno Lowagie Aug 10 '16 at 14:01
  • For the java version of the C# code given in the answer to the duplicate question, take a look at the [ReuseFont](http://developers.itextpdf.com/examples/font-examples/reuse-font-existing-pdf) example on the [official web site](http://developers.itextpdf.com/). – Bruno Lowagie Aug 10 '16 at 14:05
  • Can you please tell me how to reduce the thickness of the new text – Emerald Aug 11 '16 at 12:55

0 Answers0