1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public static void ExportPDF (){
Document document = new Document(PageSize.A4);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\test.pdf"));
document.open();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(scPane.getViewport().getWidth(), scPane.getViewport().getHeight());
// Graphics2D g2 = template..createGraphics(scPane.getViewport().getWidth(), scPane.getViewport().getHeight());
Graphics2D g2 = template.createGraphics(document.getPageSize().getWidth(),document.getPageSize().getHeight());
scPane.getViewport().print(g2);
g2.dispose();
contentByte.addTemplate(template, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
finally{
if(document.isOpen()){
document.close();}
}
} |
Partager