List of usage examples for com.itextpdf.text.pdf PdfTemplate createGraphics
public java.awt.Graphics2D createGraphics(final float width, final float height)
Graphics2D
to write on. From source file:registrosql.Registrar.java
public void PrintFrameToPDF(File file) { try {/*from ww w .j a va 2 s .co m*/ Document d = new Document(); PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(file)); d.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate template = cb.createTemplate(PageSize.LETTER.getWidth(), PageSize.LETTER.getHeight()); cb.addTemplate(template, 0, 0); Graphics2D g2d = template.createGraphics(PageSize.LETTER.getWidth(), PageSize.LETTER.getHeight()); g2d.scale(0.4, 0.4); for (int i = 0; i < this.getContentPane().getComponents().length; i++) { Component c = this.getContentPane().getComponent(i); if (c instanceof JLabel || c instanceof JScrollPane) { g2d.translate(c.getBounds().x, c.getBounds().y); if (c instanceof JScrollPane) { c.setBounds(0, 0, (int) PageSize.LETTER.getWidth() * 2, (int) PageSize.LETTER.getHeight() * 2); } c.paintAll(g2d); c.addNotify(); } } g2d.dispose(); d.close(); } catch (Exception e) { System.out.println("ERROR: " + e.toString()); } }