Footer Text alignment Issue

Hi,

I have a requirement to merge word document with pdf and i was able to do it successfully using Aspose.words(merge word documents), Aspose.pdf(convert pdf to word) java. I was able to convert pdf to word and then merge both the word documents.
Attached ‘FinalMergedDoc.docx’ and sample pdf which i converted to word. First page in the ‘FinalMergedDoc.docx’ has a footer text ‘2021 – Sample text over here’. I need to update that footer text in the rest of the pages and i was able to do it. Also i need to add the continuation of page numbers specifying the total pages once merged.
But i see below two issues:

  • Footer text is not aligned properly in page2(converted pdf) of the ‘FinalMergedDoc.docx’. It should be same as Page 1.
  • Also page number is restarting on the appended document, Page2.

Could you please help me in resolving these two issues. Attached current code used on this.

CurrentCodeSnippet.PNG (16.7 KB)
FinalMergedDoc.docx (31.3 KB)
SamplePDF.pdf (32.1 KB)

Thanks,
Sundeep.

@sveturi,

You need to adjust the Page margins. Please try using the following code:

Document doc = new Document("C:\\Temp\\FinalMergedDoc.docx");
// make the margins same as of previous section
doc.getLastSection().getPageSetup().setLeftMargin(72);
doc.getLastSection().getPageSetup().setRightMargin(72);
doc.getLastSection().getPageSetup().setTopMargin(72);
doc.getLastSection().getPageSetup().setBottomMargin(72);

doc.getLastSection().getPageSetup().setRestartPageNumbering(false);

doc.save("C:\\temp\\awjava-21.9.docx");

Thanks Hafeez for the help.
With the suggested code, page num issue is resolved now.
But with margin setting code, its messing up the entire content in the page.

WithSuggestedCode.PNG (15.9 KB)
.
Attached screenshot for reference.

Thanks,
Sundeep.

@sveturi,

The screenshot you shared shows content of some other document than the one you shared in your first post (FinalMergedDoc.docx). Can you please also provide the relevant Word document showing the undesired behavior here for our reference?

Hi Hafeez,

Please find attached document where pagenum is restarting even after using above code.
Also the footer is not proper.
And this issue is happening if there are multiple sections. Could you please help on this.

Thanks,
Sundeep.

Sample1_result.docx (650.3 KB)

@sveturi You should disable page numbering restart for each section in the document. For example see the following code:

Document doc = new Document("C:\\Temp\\Sample1_result.docx");

for (Section sect : doc.getSections())
{
    sect.getPageSetup().setRestartPageNumbering(false);
}

doc.save("C:\\Temp\\out.docx");

With position of footer content on the 5-8 pages the question is more difficult. The problem is that content of the document converted from PDF using Aspose.Pdf is represented by frames (floating objects) when you change the margins the floating content might be shifted. However the following code seems to give an acceptable result:

Document doc = new Document("C:\\Temp\\Sample1_result.docx");

for (Section sect : doc.getSections())
{
    sect.getPageSetup().setLeftMargin(doc.getFirstSection().getPageSetup().getLeftMargin());
    sect.getPageSetup().setRightMargin(doc.getFirstSection().getPageSetup().getRightMargin());

    sect.getPageSetup().setRestartPageNumbering(false);
}

doc.save("C:\\Temp\\out.docx");

Thanks Noskov !
Its working as expected for now.
Will reach out if any issue.

Appreciate your help, Support Team !

Thanks,
Sundeep.