IText creates a document with unequal page sizes

I want to create a pdf file using itext, which has unequal page sizes. I have these two rectangles:

Rectangle one=new Rectangle(70,140);
 Rectangle two=new Rectangle(700,400);

and I write in pdf as follows:

Document document = new Document();
  PdfWriter writer=  PdfWriter.getInstance(document, new FileOutputStream(("MYpdf.pdf")));

when I create a document, I have the ability to specify the page size, but I need different page sizes for different pages in my pdf. Is it possible to do this?

Eg. The first page will have a rectangle as the page size, and the second page will have a rectangle as the page size.

+4
source share
1 answer

I created an UnequalPages example that shows how it works:

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
Rectangle one = new Rectangle(70,140);
Rectangle two = new Rectangle(700,400);
document.setPageSize(one);
document.setMargins(2, 2, 2, 2);
document.open();
Paragraph p = new Paragraph("Hi");
document.add(p);
document.setPageSize(two);
document.setMargins(20, 20, 20, 20);
document.newPage();
document.add(p);
document.close();

( ) , . , open() , newPage(). ( newPage() ) ( iText, ).

+12

Source: https://habr.com/ru/post/1536843/


All Articles