import com.projity.session.SessionFactory;
public class PDFExport {
public static void export(final GraphPageable pageable,Component parentComponent) throws IOException{
final File file=chooseFile(pageable.getRenderer().getProject().getName(),parentComponent);
final JobQueue jobQueue=SessionFactory.getInstance().getJobQueue();
Job job=new Job(jobQueue,"PDF Export","Exporting PDF...",true,parentComponent);
job.addRunnable(new JobRunnable("PDF Export",1.0f){
public Object run() throws Exception{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
pageable.update();
int pageCount = pageable.getNumberOfPages();
if (pageCount>0){
ViewPrintable printable=pageable.getSafePrintable();
ExtendedPageFormat pageFormat=pageable.getSafePageFormat();
double width=pageFormat.getWidth();
double height=pageFormat.getHeight();
float startIncrement=0.1f;
float endIncrement=0.0f;
float progressIncrement = (1.0f-startIncrement-endIncrement)/pageCount;
for (int p=0;p< pageCount;p++) {
setProgress(startIncrement+p*progressIncrement);
document.setPageSize(new Rectangle((float)width,(float)height));
if (p==0) document.open();
else document.newPage();
Graphics2D g = writer.getDirectContent().createGraphics((float)width, (float)height);
printable.print(g, p);
g.dispose();
}
document.close();
}
setProgress(1.0f);
return null;
}
});
jobQueue.schedule(job);
}