Hi,
I use following code to export a jPanel to PDF:
Document document = new Document(PageSize.A4);
try {
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("C:\\temp\\test.pdf"));
document.open();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(500, 500);
Graphics2D g2 = template.createGraphics(500, 500);
double w = document.getPageSize().getWidth();
double scale= w / jPanel1.getWidth();
g2.scale(scale, scale);
jPanel1.print(g2);
g2.dispose();
contentByte.addTemplate(template, 30, 300);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (document.isOpen()) {
document.close();
}
It works fine, except for the scaling. I need the Panel to fit A4, but the
resulting document is always much smaller than A4.
Can you please point out my error, or provide me with some code that works
better ?
Thanks,
Jannis
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
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