Setting the font size in Itextpdf
32,050
So, my final snippet looks like this:
Document doc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);
float fntSize, lineSpacing;
fntSize = 6.7f;
lineSpacing = 10f;
Paragraph p = new Paragraph(new Phrase(lineSpacing,line,
FontFactory.getFont(FontFactory.COURIER, fntSize)));
doc.add(p);
It gives a perfect format for an A4 size paper with no margins and a good font size.
I hope it helps someone!
Author by
Techidiot
Unless you try to do something beyond what you have already mastered, you will never grow!
Updated on July 19, 2022Comments
-
Techidiot almost 2 years
I am working on a program where I am taking an
ASCII
file as input and converting it toPDF
usingItext
library.I am able to convert and print it, but the font size appears too small. Currently I have set the font size to
6
but, if I change it to 7, It doesn't work, it doesn't fit on thePDF
properly.Here is a part of my code snippet:
Document doc= new Document(); Rectangle test = new Rectangle(531,666); doc = new Document(test); doc.setMargins(0,0,0,0); p = new Paragraph(new Phrase(lineSpacing,line, FontFactory.getFont(FontFactory.COURIER, fntSize))); doc.add(p);
I am not able to use double with this method. Is there any other way?