package it.stefanochizzolini.clown.samples; import it.stefanochizzolini.clown.documents.Document; import it.stefanochizzolini.clown.documents.Page; import it.stefanochizzolini.clown.documents.Pages; import it.stefanochizzolini.clown.documents.PageFormat; import it.stefanochizzolini.clown.documents.contents.composition.AlignmentXEnum; import it.stefanochizzolini.clown.documents.contents.composition.AlignmentYEnum; import it.stefanochizzolini.clown.documents.contents.composition.PrimitiveFilter; import it.stefanochizzolini.clown.documents.contents.fonts.StandardType1Font; import it.stefanochizzolini.clown.files.File; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.EnumSet; /** This sample generates a series of pages from the default page formats available, both in size and orientation. @author Stefano Chizzolini (http://www.stefanochizzolini.it) @version 0.0.6 */ public class PageFormatSample implements ISample { // // // public void run( PDFClownSampleLoader loader ) { // 1. PDF file instantiation. File file = new File(); // 2. Get the document associated to the file! Document document = file.getDocument(); // 3. Populate the document! populate(document); // (boilerplate metadata insertion -- ignore it) loader.buildAccessories(document,this.getClass(),"Page Format","page formats"); // 4. Serialize the PDF file (again, boilerplate code -- see the PDFClownSampleLoader class source code)! loader.serialize(file,this.getClass().getSimpleName(),false); } // // private void populate( Document document ) { StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyNameEnum.Courier, true, false ); Pages pages = document.getPages(); for(PageFormat.SizeEnum pageFormat : EnumSet.allOf(PageFormat.SizeEnum.class)) { for(PageFormat.OrientationEnum pageOrientation : EnumSet.allOf(PageFormat.OrientationEnum.class)) { // Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. pages.add(page); // Puts the page in the pages collection. // Set the page size! page.setSize( PageFormat.getSize( pageFormat, pageOrientation ) ); // Drawing the text label on the page... Dimension2D pageSize = page.getSize(); PrimitiveFilter builder = new PrimitiveFilter(page); builder.setFont(bodyFont,32); builder.showText( pageFormat + " (" + pageOrientation + ")", // Text. new Point2D.Double( pageSize.getWidth() / 2, pageSize.getHeight() / 2 ), // Location: page center. AlignmentXEnum.Center, // Place the text on horizontal center of the location. AlignmentYEnum.Middle, // Place the text on vertical middle of the location. 45 // Rotate the text 45 degrees counterclockwise. ); builder.flush(); } } } }