I'm trying to create a PDF document with some pages in portrait and others in landscape, but seeing this example (iText7 - Page orientation and rotation) I found that the page rotates to landscape but the text also does it (PDF generated from iText7 samples), then, I need that the pages to rotate but the text continues from left to right, how in the next image.
Note: I tried to use document.getPdfDocument().addNewPage(new PageSize(PageSize.A4.rotate()));
but it works for one page, not for the next x pages.
iText is a Java library originally created by Bruno Lowagie which allows to create PDF, read PDF and manipulate them. The following tutorial will show how to create PDF files with iText. This tutorial assumes that you have basis Java and Eclipse knowledge. iText has a hierarchical structure.
This license is a commercial license. You have to pay for it. To answer your question: iText can be used for free in situations where you also distribute your software for free. As soon as you want to use iText in a closed source, proprietary environment, you have to pay for your use of iText.
iText is rooted in the Open-Source community Over 20 years ago, the code that formed the basis for the iText PDF library as we know it today was written in an open-source environment. Even today, its code remains open-source.
iText is a set of PDF tools for Java and . NET developers. This tool allows software developers to create PDF documents, perform conversions, and easily produce interactive forms that are optimized to the customer's needs.
You can do it with setting page size
For itextpdf 5.5.x
Document doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("D://qwqw12.pdf"));
doc.open();
doc.add(new Paragraph("Hi"));
doc.setPageSize(PageSize.A4.rotate());
doc.newPage();
doc.add(new Paragraph("Hi2"));
doc.newPage();
doc.add(new Paragraph("Hi3"));
doc.close();
this will create an A4-page with Hi, then an landscape-oriented page with Hi2, and last page will also be landscape-oriented. All new pages will be landscape-oriented until you don't set new page style via setPageSize()
.
For itextpdf 7.x
PdfDocument pdfDoc = new PdfDocument(new PdfWriter("D://qwqw12.pdf"));
Document doc = new Document(pdfDoc, PageSize.A4);
doc.add(new Paragraph("Hi"));
doc.getPdfDocument().setDefaultPageSize(PageSize.A4.rotate());
doc.add(new AreaBreak());
doc.add(new Paragraph("Hi2"));
doc.add(new AreaBreak());
doc.add(new Paragraph("Hi3"));
doc.close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With