IlvPrintableDocument document = new IlvPrintableDocument("A test document"); // Sets a header in the document. document.setHeader(new IlvHeader(null, "Printing Example", IlvHeader.PageKey)); // Creates the first page. IlvPage page1 = new IlvPage(); // Prints an oval on the first page. IlvPrintableObject oval = new IlvPrintableObject() { /** * Overrides the <code>print</code> method to print an oval. * It shows how to implement a <code>PrintableObject</code>. * @param dst The output <code>Graphics</code> object. * @param format The page format, which is ignored here. * @param pageIndex The page index, which is ignored here. */ public int print(Graphics dst, PageFormat format, int pageIndex) throws PrinterException { dst.drawOval(200, 200, 200, 100); return Printable.PAGE_EXISTS; } }; // Adds this new printable to the page. page1.addPrintableObject(oval); // Creates the second page. IlvPage page2 = new IlvPage(); // Prints a rectangle on the second page. IlvUnit.Rectangle area = new IlvUnit.Rectangle(5, 5, 10, 10, IlvUnit.CM); IlvPrintableRectangle rectangle = new IlvPrintableRectangle(area); page2.addPrintableObject(rectangle); // Adds the pages to the document. document.addPage(page1); document.addPage(page2); // Creates the print manager. IlvPrintingController controller = new IlvPrintingController(document); // Previews the document. controller.setPreviewMode(IlvPrintPreviewPanel.CONTINUOUS_MODE); controller.printPreview(JOptionPane.getRootFrame());