I am converting a HTML file to PDF. Almost everything works fine so far, but I am at a point, where I don’t know how to proceed. Is there an option to set different margins on pages following the first page? So far I am using the PageSetup methods like setTopMargin to set the margin for the entire document.
Thanks for your reply. I am a little bit lost on how I go about iterating through all the nodes in the document to get the last node of the first page. Could you please provide some sample code snippet for me to work with? My html file is fairly basic and includes ul/li, div and span tags, if that is relevant for this step.
Document doc = new Document(MyDir + "input.html");
DocumentBuilder builder = new DocumentBuilder(doc);
LayoutCollector collector = new LayoutCollector(doc);
int pageIndex = 1;
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for(Paragraph para : paragraphs)
if (collector.getStartPageIndex(para) == 2)
//Move the cursor to the previous node of paragraph
//that is last node on first page of document
PageSetup pageSetup = builder.getCurrentSection().getPageSetup();
doc.save(MyDir + "output.docx");
Hey, sorry for the late response.
I managed to get this to work, setting up different margins for pages following the first one. However, the changes do not display when converting to PDF. It works fine with .doc for example.