How to use the full size of a page?

Tags: marginspage sizeiText 7

I managed to set the size of the PDF document I'm creating to the size I need (~3cm x ~7cm), but the content inside the page is only using a third of the space. I need to use the whole available space.

Posted on StackOverflow on Apr 17, 2015 by user1913644

You currently have something like:

Rectangle rect = new Rectangle(85, 200);
PdfDocument pdf = new PdfDocument(new PdfWriter(“full_size_page.pdf”));
Document document = new Document(pdf, new PageSize(rect));

Try this instead:

Rectangle rect = new Rectangle(85,200);
PdfDocument pdf = new PdfDocument(new PdfWriter(“full_size_page.pdf”));
Document document = new Document(pdf, new PageSize(rect));
pdf.addNewPage();
document.setMargins(0,0,0,0);
document.close();

The 0 values are the size of the margins (left, right, top, bottom). If you omit them, they are 36 user units by default (on either side). If your rectangle measures 85 by 200 user units, using the default margins leaves you 13 by 128 user units to add content. This is somewhat consistent with what you experience.

Click this link if you want to see how to answer this question in iText 5.