Hi, I admit my question was not very clear. Sorry.
However, after heavy searching THE NET I found the solution to most of my problems: Document doc = new Document(PageSize.A4); PdfWriter out = null; try { out = PdfWriter.getInstance(doc, new FileOutputStream(getNewFilepath("C:/tmp/itexttest", "itextPDF") + ".pdf")); } catch (IOException e) { System.out.println("Exception opening pdf reader: " + e.getLocalizedMessage()); return; } catch (DocumentException e) { System.out.println("Exception opening pdf reader: " + e.getLocalizedMessage()); return; } doc.open(); // iText font != java.awt.Font ! FontFactory.registerDirectories(); // register all fonts in the usual directories doc.addTitle("A PDF output test"); doc.addCreationDate(); doc.addCreator("M. Harig"); doc.addProducer(); Paragraph p = new Paragraph(" A PDF output test"); p.setAlignment(1); doc.add(p); ///// print image // print image title p = new Paragraph("Image 1"); p.setAlignment(0); doc.add(p); JFrame frame = new JFrame("sdf"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pnl = new JPanel(); pnl.add(new JButton("a button with a very long text")); pnl.setPreferredSize(new Dimension(300,100)); frame.add(pnl); frame.pack(); frame.setVisible(true); // Because of a bug in IText (?), we have to set another LAF // if we are using Substance LAF !!!! // don't know if saving and restoring the old one is necessary PanelUI old = pnl.getUI(); pnl.setUI((PanelUI)javax.swing.plaf.basic.BasicPanelUI.createUI(pnl)); BufferedImage img = new BufferedImage(pnl.getWidth(), pnl.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D img2D = img.createGraphics(); pnl.print(img2D); float viewWidth = out.getPageSize().getWidth() - doc.leftMargin() - doc.rightMargin(); double scaleX = viewWidth / pnl.getWidth(); img2D.scale(scaleX, scaleX); // keep aspect ratio p = new Paragraph(); com.lowagie.text.Image itextImg = com.lowagie.text.Image.getInstance(img, Color.BLUE, false); p.add( itextImg ); doc.add( p ); // restore old LAF pnl.setUI(old); ///// trailing text doc.add(new Paragraph("Trailing text. This text should be printed below the image.")); doc.close(); Regards, Michael > I don't understand the question. > Can you please tell us if you're using PdfGraphics2D? > If so, what is the problem? >> Hi, >> >> I want to print a JPanel in a PDF document. >> Structure will be: a title, some arbitrary text, the JPanel, some >> tables, more arbitrary text. >> >> The examples I found that print images use either a PDFContentByte or >> are some HTML, XML processing stuff using IText Image. >> >> When using a template and PDFContentByte, one needs to know the position >> of the last written text to place the graphic below, and then one must >> place the next elements (the tables and more text) after that. I didn't >> find out how to achieve these 2 things, nor how to convert a JPanel >> graphic to a IText Image for the other approach. >> >> Any hints? ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/