I have a frame and there are several components on it. How do I paint this JFrame using iText?
I write some code as follow(but does not work):
public void PrintFrameToPDF(Component c, 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(c.getWidth(), c.getHeight());
Graphics2D g2d = template.createGraphics(c.getWidth(), c.getHeight());
c.paintAll(g2d);
c.addNotify();
c.validate();
g2d.dispose();
d.close();
} catch (Exception e) {
//
}
}