We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Incorrect pagination causing problems

Aspose.Words 10.0.7 seems to sometimes incorrectly update the page numbers when I call Document.UpdateFields and Document.UpdatePageLayout. If I open the document in Word, select the entire document, and press F9, then I do see the page numbers I'd expect.

The problem occurs when I try to add a section break at the end of every page. The paragraphs are kept together, so a paragraph can't be split over 2 pages. I wrote code to add the page number as hidden text at the end of every paragraph. added the section breaks between paragraphs with different page numbers, then later removed this hidden text.Since the page numbers were hidden text, I would not expect the page numbers to affect the pagination of the document.

The problem occurs when I open the attached document using Aspose.Words, call UpdateFields and UpdatePageLayout on the resulting document, then save it.

I'm using 10.0.7 since I don't have a license for a newer version. The trial license for 11.1.0 does not work on large files, so I can't easily reproduce the problem there. If you look at the top of p. 14 you can see that page number for the first two paragraphs appears to be p. 13, not p. 14. After F9 I see 14 as the page number throughout the page. Make sure to show hidden text when viewing the Word file.

Is there a fix that you can provide for Aspose.Words 10.7.0? If not, is there a workaround you can provide? And if you can't help with either of these options, is the problem fixed in Aspose.Words 11.1.0 or will it be fixed soon in some upcoming release of Aspose.Words?

10.7.0 broke backward compatibility for a problem related to one of the issues I raised in <a href="https://forum.aspose.com/t/53724</a>. I will describe this problem in a separate thread.</div><div><br></div><div>Mark Novick</div><div>software engineer</div><div>ASC</div><div><br></div><div><br></div><div><br></div>

Please supply code in Visual Basic, not C#.


Hi Mark,


Thank you for inquiry. Unfortunately, it is difficult for us to say what is the problem. Could you please create a simple console application which reproduces the issue on your side and attach it here? We will take a closer look into what’s happening and provide you with some further feedback.

As I mentioned in my original message, my program just reads a document, calls UpdateFields and UpdatePageLayout, then saves the result.


Imports Aspose.Words
Module Module1
Sub Main()
Dim doc As New Document(“C:\pageBugInput.doc”)
doc.UpdateFields()
doc.UpdatePageLayout()
doc.Save(“c:\pageBugOutput.doc”)
End Sub
End Module

The problem also occurs with the trial version of the most recent version of Aspose.Words, 11.1.0. I attached a copy of the file that has the wrong page numbers inside the document at the end of the first 2 paragraphs on the 3rd page. They are assigned page number 2, but really they should be page number 3. Note the page number appears as hidden text there, so show all formatting marks in Word. If you choose the entire document in Word, and press F9, then the correct page numbers appear.

Hi Mark,


Thanks for the additional information. While using latest Aspose.Words 11.1.0. I managed to reproduce this problem on my side. I have logged your issue as WORDSNET-6007 into our bug tracking system. Your request has also been linked to the appropriate issue. Once we sort it out, we will let you know. Sorry for inconvenience.


Hello Mark and all Aspose Team Respondents,

I have posted a forum request of a similar nature, my code is in C#. I'm going to make a leap of faith here and say I just may have solved the problem. :) You all will be relieved to know there may not be a bug after all!

What finally solved this issue, now that it is perfectly obvious is to call the TOC within the manually coded AppendDocument() method. It could be the direct .AppendDocument() may not be working as it should.

Here is our original code. The TOC methods were being called prior to ReportAssembly(). The solution of applying these methods after was attempted, it did not work. The page numbers were always off.

//docGenerated.UpdateFields();//Updates the TOC.

//docGenerated.UpdatePageLayout(); //Puts the page numbers into the TOC

if (!IsDraft)

{

docGenerated.Protect(ProtectionType.ReadOnly);

}

ReportAssembly(docGenerated);

Within ReportAssembly(), AppendDocument() is called:

AppendDocument(docTemplateTitlePage, docGenerated, ImportFormatMode.KeepSourceFormatting);

The TOC methods were placed in the manually coded AppendDocument() with signature as below. (as opposed to using the document.AppendDocument(Document sourceDoc, ImportFormatMode mode) method)

public void AppendDocument(Document templDoc, Document genDoc, ImportFormatMode mode)

{

foreach (Section srcSection in genDoc)

{

Node dstSection = templDoc.ImportNode(srcSection, true, mode);

templDoc.AppendChild(dstSection);

}

templDoc.UpdateFields();//Updates the TOC.

templDoc.UpdatePageLayout(); //Puts the page numbers into the TOC

}

Bingo, problem solved.

If others are not using AppendDocument(), this obviously won't be a solution. But this works perfectly for us on this end. Perhaps a solution for all might be to create a new document in this method, append each section of the imported document into it, do the TOC updates?

At any rate, this solved my issue.

Mike

Hi Mike,


Thanks for providing the additional information.

Please note that when you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call Document.UpdateFields method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document. Also, calling Document.UpdatePageLayout method helps in rebuilding the page layout of the document.

Best Regards,

I don’t think Mike’s suggestion helps me. I am already calling Document.UpdateFields and Document.UpdatePageLayout, as I mentioned in
https://forum.aspose.com/t/63436 and

https://forum.aspose.com/t/63436. The problem occurs even when I don’t append documents together. I would have expected calling UpdateFields and UpdatePageLayout would generate the same page numbers as selecting the entire document in Word and pressing F9 to update the fields. Unfortunately it appears that the 2 methods sometimes yield different results. Word shows the correct page numbers in this case, but Aspose.Words does not.


It looks like some of my co-workers have found a workaround by modifying the Word file so that the pagination problem does not occur. It would help if Aspose couldd mention how the Word file can be modified slightly to avoid the problem, even if there’s no simple way to correct the problem within Aspose.Words.

Thanks,
Mark Novick
software engineer
ASC

Hi

Thank you for additional information. It is perfect that you managed work the problem around. The problems with pagination might occur if your document has some content that Aspose.Words does not support or not fully support upon building document layout. For example: Floating tables and shapes, frames, MathML formulas.

Best regards,

It looks like the problem might be because in Word 2007 under Word Options->Advanced, Compatibility Options it says to lay out this document as if created in Custom. Normally it says “Microsoft Office Word 2003” for the documents I’m handling. Maybe the problem occurs because some odd custom settings are not handled by Aspose.Words.


Perhaps Aspose support could detect if unsupported options are used in the document which might cause problems, and if they occur, then support can suggest to users they change these options to supported options.

Thanks,
Mark Novick
software enginner
ASC

Hi
Mark,


Thanks for the additional information. Unfortunately, WORDSNET-6007 is not resolved yet. Currently, this issue is pending for analysis and is in the queue. Once the issue is analyzed, we will then be able to provide you more information on this. Sorry for the inconvenience.

Best Regards,

The issues you have found earlier (filed as WORDSNET-6007) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.