/* * This class is part of the book "iText in Action - 2nd Edition" * written by Bruno Lowagie (ISBN: 9781935182610) * For more info, go to: http://itextpdf.com/examples/ * This example only works with the AGPL version of iText. */ package part4.chapter13; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfBoolean; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfNumber; import com.itextpdf.text.pdf.PdfWriter; public class PrintPreferencesExample { /** The resulting PDF file. */ public static final String RESULT = "results/part4/chapter13/printpreferences.pdf"; /** * Creates a PDF with information about the movies * @param filename the name of the PDF file that will be created. * @param pagelayout the value for the viewerpreferences * @throws DocumentException * @throws IOException */ public void createPdf(String filename) throws IOException, DocumentException { // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE); writer.addViewerPreference(PdfName.NUMCOPIES, new PdfNumber(3)); writer.addViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); // step 5 document.close(); } /** * Main method. * * @param args no arguments needed * @throws DocumentException * @throws IOException */ public static void main(String[] args) throws IOException, DocumentException { new PrintPreferencesExample().createPdf(RESULT); } }