Hello everyone, this is my first email to this list. I am trying to use iText to create pdfs with simple text using different fonts. I am having an issue with the text being chopped off when I try to align the text based on ascender and descender. I have attached the pdf in question with this email so that everyone can take a look. I am using the following function to create the pdf. If anyone please help me with suggestions on how to prevent the text chopping issue, I'd really appreciate that.
public void createPdf() throws DocumentException, IOException {
FontFactory.registerDirectory("/var/fonts/", true);
String text = "yfd";
float width = 100;
float height = 50;
float fontSize = 20;
String fontName = "SquarePegROB";
Font font = FontFactory.getFont(fontName, "", BaseFont.EMBEDDED,
fontSize, 0, new BaseColor(new Color(0, 0, 0)));
Paragraph contentParagraph = new Paragraph(text, font);
contentParagraph.setLeading(fontSize * 1.2f);
Document doc = new Document(new Rectangle(width, height));
doc.setMargins(0, 0, 0, 0);
FileOutputStream fos = new FileOutputStream( new
File("/home/mhossain/itext/pdfs/pdftest.pdf"));
PdfWriter.getInstance(doc, fos);
PdfPTable table = new PdfPTable(1);
table.setWidthPercentage(100);
table.setTotalWidth(width);
table.setLockedWidth(true);
table.setSpacingBefore(0);
table.setSpacingAfter(0);
PdfPCell cell = new PdfPCell(contentParagraph);
cell.setColspan(1);
cell.setFixedHeight(height);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
cell.setUseAscender(true);
cell.setUseDescender(true);
cell.setPadding(0);
table.addCell(cell);
doc.open();
doc.add(table);
doc.close();
fos.close();
}
Sincerely,
Mir
pdftest.pdf
Description: Adobe PDF document
------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
