Search code examples
pdflayoutitextmargins

iText: custom left and right margins for header


I created a java class that creates a pdf document. This document has a header composed by a table with text and images, which is present on every page.

I put the header with PdfPageEventHelper.onStartPage() and the code is as follows:

Document doc = new Document();
ByteArrayOutputStream baos= new ByteArrayOutputStream(); 
PdfWriter writer = PdfWriter.getInstance(doc, baos);
doc.setMargins(Utilities.millimetersToPoints(30), Utilities.millimetersToPoints(20),   Utilities.millimetersToPoints(10), Utilities.millimetersToPoints(15));
writer.setPageEvent(new HeaderFooter(Variables...));
doc.open();

... do other stuffs...

I have the following problem: I would like to have different left and right margins for the header respect to the rest of the document: in particoular the header table should have the left side more on left respect to the body.

It it possibile to do this? Is there a simple solution for my problem? I read the documentation but I can't find the simplest solution.


Solution

  • Solved: i putted the header in a Paragraph and set the left margin negative... brutal but effective :)