Wednesday, 15 June 2011

itext pdf PageSize.LEGAL_LANDSCAPE.rotate() does not print -


I have created a program to write a two-page PDF, the first page is the picture and the other is a scenario, it creates a PDF But when I print that file, it does not print the second page i.e. scenario page.

Below is my 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.phileNotFoundException; Import java.io.FileOutputStream; Public class test PDF {Public Static Zero Main (string agrees []) throws document exception, file notfound exception {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 Adjust Page (document); // PAGE2 addSecondPage (document); Document.close (); } Public static document addFirstPage (document document) throws documents exclamation {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 throws AddSecondPage (document document) 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 your code with: Rectangle A4 = PageSize A4; Rectangle A4 Landscape = a4.rotate (); Document.setPageSize (a4Landscape);


No comments:

Post a Comment