Itextsharp Generate PDF document with Portrait and Landscape -


i using itextsharp generate pdf document. currently, html contents converted pdf document. default page orientation portrait.

however, requirement is create pdf document page in portrait , in landscape.

the following line generates pdf document portrait orientation

    document.setpagesize(pagesize.a4); 

and, if change line creates whole document in landscape.

        document.setpagesize(pagesize.a4.rotate()); 

how can generate pdf mixed portrait , landscape orientation?

kindly advise.

you have need. method using correct one. can use more once, aware of fact need change page size before new page created:

document document = new document(); pdfwriter.getinstance(document, new system.io.filestream(filename, system.io.filemode.create)); document.setpagesize(pagesize.a4); document.open(); document.add(new paragraph("hi in portrait")); document.setpagesize(pagesize.a4.rotate()); document.newpage(); document.add(new paragraph("hi in landscape")); document.close(); 

as can see, set page size a4 in portrait before open() document. add content page, , decided set page size next page a4 in landscape. take effect after new page starts. can triggered automatically itext when add content doesn't fit current page. or can trigger invoking newpage(). in example, second paragraph added page in landscape.

see itext create document unequal page sizes java example.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -