@Override
public boolean performFinish() {
//create the document
Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize());
Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize); //rotate if we need landscape
Document document = new Document(pageSize);
try {
//Basic setup of the Document, and get instance of the iText Graphics2D
// to pass along to uDig's standard "printing" code.
String outputFile = page1.getDestinationDir()+
System.getProperty("file.separator")+ //$NON-NLS-1$
page1.getOutputFile();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
document.open();
Graphics2D graphics = null;
Template template = getTemplate();
int i = 0;
int numPages = 1;
do {
//sets the active page
template.setActivePage(i);
PdfContentByte cb = writer.getDirectContent();
Page page = makePage(pageSize, document, template);
graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());
//instantiate a PrinterEngine (pass in the Page instance)
PrintingEngine engine = new PrintingEngine(page);
//make page format
PageFormat pageFormat = new PageFormat();
pageFormat.setOrientation(PageFormat.PORTRAIT);
java.awt.print.Paper awtPaper = new java.awt.print.Paper();
awtPaper.setSize(pageSize.getWidth() * 3, pageSize.getHeight() *3);
awtPaper.setImageableArea(0, 0, pageSize.getWidth(), pageSize.getHeight());
pageFormat.setPaper(awtPaper);
//run PrinterEngine's print function
engine.print(graphics, pageFormat, 0);