Hello,
We are seeing unexpected output when we merge three documents and generate a PDF.
Relevant notes:
- The first document (aka the “base doc”) has four footnotes.
This document has 2 pages and the footnotes are expected to appear at the bottom of page 2.
- The second document has 3 endnotes - which are formatted to appear at the end of the section.
This document has 2 pages and the endnotes are expected to appear at the end of page 2.
- The third document has no footnote or endnotes but will be included in the merged document.
This document has 1 page.
- When these documents are merged, they are separated by a continuous section break.
- The first paragraph of document 2 and 3 have the “page break before” setting enabled.
- When the PDF is generated from the merged documents, it correctly produces a 5 page PDF.
However, the endnotes from the second document appear on the 2nd page of the PDF - which pertains to the 1st document.
This behavior can be seen in the latest Aspose Words for Java version 22.4, the attached documents and the following Java code:
final String fileFolder = "[PATH]";
final Document baseDoc = new Document(fileFolder + "Footnotes.docx");
final String[] mergeDocs = { fileFolder + "Endnotes.docx",
fileFolder + "Document3.docx"};
for (String docToMerge : mergeDocs) {
Document mergeDoc = new Document(docToMerge);
// add a continuous section break on the mergeDoc
mergeDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
// merge the two documents
baseDoc.appendDocument(mergeDoc, ImportFormatMode.USE_DESTINATION_STYLES);
baseDoc.cleanup();
}
// save the base Doc as PDF
final String pdfFile = fileFolder + "MergedDocs.pdf";
Files.deleteIfExists(Paths.get(pdfFile));
baseDoc.save(pdfFile, new PdfSaveOptions());
System.out.println("Created merged PDF File: " + pdfFile);
Running the above code should produce a file named MergedDocs.pdf
. If you view the PDF and navigate to page 2, you should see that the endnotes from Endnotes.docx
appear along with the footnotes from Footnotes.docx
. We expect the endnotes to appear on page 4 of the PDF.
Environment Details:
- Aspose Words for Java 22.4
- Java version 1.8.0_211
- Windows 10 OS (but also reproducible under Linux).
File description in the MergedFootnotesEndnotes.zip
(96.9 KB) attachment contains:
-
Footnotes.docx: Base DOCX file with footnotes used by the code above.
-
Endnotes.docx: DOCX file with endnotes used by the code above.
-
Document3.docx: DOCX file with no footnotes or endnotes used by the code above.
-
MergedDocs.pdf: PDF file generated after running the code above (on our environment).
Thank you!
@oraspose Thank you for reporting this problem to us. For a sake of correction it has been logged as WORDSNET-23861. We will keep you informed and let you know once it is resolved.
Could you please also confirm this PDF document is your expected output? ms.pdf (134.5 KB)
Hi Alexey
Thank you for your prompt response and for looking into this issue. I took a look at the PDF you attached “ms.pdf”. While it is certainly much better than the PDF we provided, it still seems off. Specifically, we expect the endnotes to appear on the 4th page of the PDF (not at the end of the PDF).
If you open the Endnotes.docx
in MS Word, right-click on any of the endnotes and choose “Note Options” - you should see that the endnote settings indicate that they should appear at the “End of Section”. Given that we are adding a section break between the merged documents - our expectation is that this setting should allow the endnotes to appear at the end of the 2nd Section - which translates to page 4 of the PDF.
On the other hand, if the endnotes setting was set to “End of Document” - then we would expect the endnotes to appear at the end of the PDF - similar to the one you’ve attached. But in this case, the “End of Section” option should remain intact on the merged document.
Thanks again!
@oraspose The problem is that footnote and endnote options are applied to the whole document. In your case the baseDoc
has endnote position set to EndnotePosition.END_OF_DOCUMENT
. And that is why if you save your output document to DOCX endnotes appears at the end of the document, like in PDF I have attached.
Thanks again Alexey.
You make a good point about the Footnotes.docx
file having the endnotes setting to the “End of Document”; thus when the documents are merged, this setting is inherited by the Endnotes.docx
document.
However, when I changed the endnote setting in the Footnotes.docx
to “End of Section” and reran the code above, I’m now getting a NullPointerException with the following stack:
java.lang.NullPointerException
at com.aspose.words.zzXm9.zzWMR(Unknown Source)
at com.aspose.words.zzXfX.zzWXH(Unknown Source)
at com.aspose.words.zzXfX.zzXWJ(Unknown Source)
at com.aspose.words.zzXOS.zzWRc(Unknown Source)
at com.aspose.words.zzXOS.zzWTK(Unknown Source)
at com.aspose.words.zzXOS.zzuE(Unknown Source)
at com.aspose.words.zzXOS.zzYUy(Unknown Source)
at com.aspose.words.zzrM.zzZ60(Unknown Source)
at com.aspose.words.zzrM.zzZcw(Unknown Source)
at com.aspose.words.zzrM.zzXWr(Unknown Source)
at com.aspose.words.zzrM.zzXVG(Unknown Source)
at com.aspose.words.zzWhs.zzZPF(Unknown Source)
at com.aspose.words.zzYFi.zzmQ(Unknown Source)
at com.aspose.words.zzc7.zzZPF(Unknown Source)
at com.aspose.words.zzYVE.zzWT9(Unknown Source)
at com.aspose.words.zzWA9.zzW9v(Unknown Source)
at com.aspose.words.Document.updatePageLayout(Unknown Source)
at com.aspose.words.Document.zzY06(Unknown Source)
at com.aspose.words.Document.getPageCount(Unknown Source)
at com.aspose.words.zzXKH.zzVOH(Unknown Source)
at com.aspose.words.zzXKH.zzXWJ(Unknown Source)
at com.aspose.words.zzK4.zzXWJ(Unknown Source)
at com.aspose.words.Document.zzVOH(Unknown Source)
at com.aspose.words.Document.zzXWJ(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)
at ....
I suspect this is might be the same underlying issue as WORDSNET-23860:
A Document with Footnotes and Endnotes produces a NullPointerException when converting to PDF
But regardless, would you agree that changing the endnote setting in the Footnotes.docx
file to “End of Section” should produce our expected results and show the endnotes on page 4 of the PDF (after the NullPointerException
is fixed)?
Thanks again.
@oraspose
Yes, this is a problem logged as WORDSNET-23860.
Yes, endnotes and footnotes must be rendered the same way they are shown in MS Word.
The issues you have found earlier (filed as WORDSNET-23860,WORDSNET-23861) have been fixed in this Aspose.Words for Java 22.8 update also available on Maven.
Hello again.
We are currently evaluating the latest version of Aspose.Words (24.1) and noticed that while the issue WORDSNET-23860 “A Document with Footnotes and Endnotes produces a NullPointerException when converting to PDF”(A Document with Footnotes and Endnotes produces a NullPointerException when converting to PDF ) has been fixed, the other issue WORDSNET-23861 is fixed only partially - meaning the footnotes are shown correctly now, but the endnotes are not shown at the end of the section even when the setting is the “Endnotes.docx” document is “End of section”.
Please use the same documents attached earlier:
- Footnotes.docx: Base DOCX file with footnotes used by the code above.
- Endnotes.docx: DOCX file with endnotes used by the code above. Note that endnotes have location “End of section” in the Note options of this document.
- Document3.docx: DOCX file with no footnotes or endnotes used by the code above.
Can you please take a look at your convenience?
Thank you.
@oraspose Endnotes location are set per document basis not per section. So the endnotes location from the base document is used in the final document. In the base document it is set to EndnotePosition.EndOfDocument
. That is why endnotes are placed at the end of the document, this is an expected behavior.