Extra blank page appearing after TOC page- when TOC-TOT-TOF are enabled

Hi Team,


We have a document (PFA) which when converted to PDF has an additional blank page after the TOC page. Can you please let us know why an additional page is created after the TOC page?

Code:

PFA - TestAsposeWord.java.txt


Hi Satyendra,


Thanks for your inquiry. Please upgrade to the latest version of Aspose.Words 14.6.0 from the following link. I hope, this helps:
http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/entry557800.aspx

In case the problem still remains, please attach Aspose.Words generated PDF file which shows the undesired behavior here for our reference. We will investigate the issue further on our end and provide you more information.

Best regards,

Hi Hafeez,


I have tested this with 14.6.0 and I can still see that additional blank page.
I don’t understand why do you want to push such things on us back again without testing the same at your end? This to and fro process will waste both your precious time as well as mine.

Anyways, I have attached the output PDF along with this message.
Please let me know if you need more details.

Thanks,
Satyendra

Hi Satyendra,


Thanks for your inquiry. This is not a bug in Aspose.Words but an expected behavior. You can verify by producing a DOCX file using Aspose.Words and then “Save As” to PDF format using Microsoft Word. MS Word does not display 2nd page but it can be seen in MS Word generated PDF too. If we can help you with anything else, please feel free to ask.

Best regards,

Hi Hafeez,


So do you mean that Aspose converts a doc file to a docx file and then transform it to PDF?
Why do we need to worry about how a docx is converted to PDF when we are processing a doc file?

And, if I save the doc file to PDF using MS Word “Save As”, then the PDF generated looks fine and that is what is expected out of Aspose.Words.

The extra blank page created either looks like an issue with Aspose while creating PDF, or some code that is creating additional section/para etc in the document.

Thanks,
Satyendra

Hi Satyendra,


Thanks for your inquiry. I meant if you open attached test.docx with MS Word 2013, it doesn’t display 2nd empty page but it appears when you convert it to PDF using MS Word 2013.

Please try executing the following code and see if it helps:
Document doc = new Document(getMyDir() + “DTS_6.5.0_SP3_WithBookmark_Markup.doc”);
DocumentBuilder builder = new DocumentBuilder(doc);

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

StringBuilder strBuilder = new StringBuilder();
strBuilder.append("\o “1-”).append(9).append("<font color=“PURPLE”>"");
strBuilder.append("\h");
strBuilder.append("\z");
strBuilder.append("\u");

builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

builder.moveToSection(0);
builder.startBookmark(“Table Of Contents”);
builder.write("");
builder.endBookmark(“Table Of Contents”);
pdfSaveOptions.getOutlineOptions().getBookmarksOutlineLevels().add(“Table Of Contents”, 1);

Field myToc = builder.insertTableOfContents(strBuilder.toString());
myToc.update();

doc.save(getMyDir() + “out.pdf”, pdfSaveOptions);

Best regards,

I do see that when I conveted test.docx to PDF using MS Word, then an extra blank page appears.
But the source document that I attached in a “.doc” and not ".docx"

I am sorry, but I am not able to understand why are you taking a docx example in case of a .doc.
Can you please help me understand this?


Thanks,
Satyendra

Hi Satyendra,


Thanks for your inquiry. For the sake of any correction in Aspose.Words API, I have logged this problem in our issue tracking system as WORDSNET-10480. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Any ETA available for this issue? Please share.


Thanks,
Satyendra

Hi Satyendra,


Thanks for your inquiry. This issue is pending for analysis and unfortunately at the moment we cannot provide you any reliable estimate. We will inform you as soon as this issue is resolved. We apologize for any inconvenience.

Best regards,

Hi Satyendra,


Thanks for being patient. Regarding WORDSNET-10480, our development team has completed the analysis of this issue and has come to a conclusion that this issue and the undesired behaviour you’re observing is actually not a bug in Aspose.Words. So, we will close this issue as ‘Not a Bug’.

Actually, the attached out.doc does have a blank page after the first page in Microsoft Word as well. The page is added because of section break (Odd page) on the first page. Microsoft Word does not show this blank page when editing the document in “Print layout”. However, it adds it when printing or when saving to Pdf.

The problematic section properties (odd page start) come from the original document (DTS_6.5.0_SP3_WithBookmark_Markup.doc) where the first section starts from odd page. The first page is page 1 (odd), so there is no blank page in the original document. As you prepends a new Section that fills one page only, Microsoft Word adds a blank page so that the second section starts from page 3 (odd). Aspose.Words does the same.

As a workaround, you may use the following code before saving the Document instance to PDF:

foreach (Section sec in doc.Sections)

sec.PageSetup.SectionStart = SectionStart.NewPage;


I hope, this helps.

PS: It is also a good idea to update the added TOC field in the very end of your code. Currently, after the field is updated, there are some document model manipulations. So, page numbers in TOC field calculated before those changes may not match the final document model.

Best regards,