I am working on a program where I am taking an ASCII
file as input and converting it to PDF
using Itext
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 the PDF
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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With