Hi Banjos For starters you are mixing pixels and points.
Your pdf document is in points. Your panel is in pixels. You need to: a) find out what your pixel per inch value is, likely 96 but not guaranteed. Most Modern apps define their own pixel value. B) If you are 96 then points = (pixels * .75) Otherwise, you will need yo figure out the value that gets you to 72. (Points per inch) - Bill Ensley www.bearprinting.com ----- Original Message ----- From: [email protected] To: [email protected] Sent: Thu, 17 May 2012 03:54:35 -0700 (PDT) Subject: [iText-questions] Scaling imported Swing Elements 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
