itext pdf PageSize.LEGAL_LANDSCAPE.rotate() does not print -
i have created program write pdf having 2 page, first page portrait , second 1 landscape. creates pdf when print file not print second page i.e. landscape page.
below code
/******************/ import com.itextpdf.text.document; import com.itextpdf.text.documentexception; import com.itextpdf.text.element; import com.itextpdf.text.pagesize; import com.itextpdf.text.paragraph; import com.itextpdf.text.pdf.pdfwriter; import java.io.filenotfoundexception; import java.io.fileoutputstream; public class testpdf { public static void main(string args[]) throws documentexception, filenotfoundexception { document document = new document(); pdfwriter.getinstance(document, new fileoutputstream("/home/devang/test.pdf")); document.setmargins(10.0f, 10.0f, 20.0f, 2.0f); document.open(); //page1 addfirstpage(document); //page2 addsecondpage(document); document.close(); } public static document addfirstpage(document document) throws documentexception { document.addtitle("test pdf"); paragraph paragraph = new paragraph(); paragraph.setalignment(element.align_center); paragraph.add("page 1"); paragraph.add("\npage 1"); paragraph.add("\npage 1"); paragraph.add("\npage 1"); paragraph.add("\npage 1"); document.add(paragraph); return document; } public static document addsecondpage(document document) throws documentexception { document.setpagesize(pagesize.legal_landscape.rotate()); document.newpage(); document.addtitle("test pdf"); paragraph paragraph = new paragraph(); paragraph.setalignment(element.align_center); paragraph.add("page 2"); paragraph.add("\npage 2"); paragraph.add("\npage 2"); paragraph.add("\npage 2"); paragraph.add("\npage 2"); document.add(paragraph); return document; } }
thanks in advance.
replace code with:
rectangle a4 = pagesize.a4; rectangle a4landscape = a4.rotate(); document.setpagesize(a4landscape);
Comments
Post a Comment