1
Would it be possible to convert a form to pdf or print it ? made in java, and are in a database as well.
1
Would it be possible to convert a form to pdf or print it ? made in java, and are in a database as well.
3
Try the code below if you need more references or examples try the link below:
Here: https://community.oracle.com/thread/1164777?start=0&tstart=0
public void PrintFrameToPDF(File file) {
        try {
            Document d = new Document();
            PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(file));
            d.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate template = cb.createTemplate(PageSize.A4.getWidth(),PageSize.A4.getHeight());
            cb.addTemplate(template, 0, 0);
            Graphics2D g2d = template.createGraphics(PageSize.A4.getWidth(),PageSize.A4.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.A4.getWidth()*2,(int)PageSize.A4.getHeight()*2);}
                    c.paintAll(g2d);
                    c.addNotify();
                }
            }
            g2d.dispose();
            d.close();
        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
        }
    }
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Could you be more specific? @Prostetnic Vogon Jeltz
– Roger Oliveira
I have a registration form in a jFrame, which is registered in a comic book, I would like to convert it into pdf and print it.
– Prostetnic Vogon Jeltz