Free Support Forum - aspose.com

Incorrect page numbering when saving as .PDF

I am using Aspose.Words dll version 6.3.0.0. I am merging several documents into one, and I want the page numbering to re-start with each section. When I save the aggregated file as a .doc file, it is numbered correctly. However, if I save the file as a .pdf, the first page of each section is 1, while the other pages are numbered with the cumulative page number.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Here’s a simplified code example:

Document doc = new Document()

// Append multiple files to doc

AddFiles(doc);

doc.Save("Plan.doc");

doc.Save("Plan.pdf");

Plan.doc will have these correct page numbers: 1, 2, 3, 1, 2, 1, 2, 3, 4

Plan.pdf will have these incorrect page numbers: 1, 2, 3, 1, 5, 1, 7, 8, 9

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please attach your documents here for testing? I will check the issue on my side and provide you more information.

Also, please try using the latest version of Aspose.Words (7.0.0). You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards.

I just upgraded to v.7.0.0 and I am still having a problem. The behavior has changed some, though. The page numbers in the produced Word .doc are correctly labeled 1,2,3,1,2,3,4,5,6. The page numbers in the produced .pdf file are 1,1,1,4,4,4,4,4,4.

I've attached a zip file containing the following files:

TOC.docx and Section1.doc - these individual files are merged into a document object.

Plan.doc - product of saving the document object with a .doc file extension

Plan.pdf - product of saving the document object with a .pdf file extension

Thanks for your prormpt assistance with this matter.

Regards,

Darwin R. Pinder, Jr.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I managed to reproduce the problem on my side. You will be notified as soon as it is resolved.

Best regards.

Mr. Noskov,

I just wanted to follow up on this issue with you. Are you making progress towards a fix? I'm getting a lot of pressure from my boss, as we can't go live with our new features until this is resolved.

Thanks,

Darwin Pinder

Hi <?xml:namespace prefix = st1 ns = "urn:schemas:contacts" />Darwin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Unfortunately, the issue is still unresolved. We will let you know once the issue is fixed. I apologize for inconvenience.

Best regards,

This issue has been identified for two months now, and it is becoming an embarrassment for me and my company. My manager has asked for a progress report on the resolution of the page numbering bug. Is there anything you can tell me besides "the issue is still unresolved"? Thanks for your time.

Regards,

Darwin R. Pinder, Jr.
MCSD, MCDBA, OCA

Hi Darwin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Unfortunately, we did not have a chance to resolve this issue yet. There are a lot of other important issues we have to work on. I added your request to my monthly report, so its priority will be increased. Please expect a reply before the next hotfix (within few weeks). We might just fix the problem by then or provide you more information.

Best regards.

Has there been a hot-fix provided for this issue yet? Thanks!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I tried converting your document to PDF using the latest version of Aspose.Words and page numbers are correct. Could you please check with the latest version on your side and confirm that the issue is resolved. Then I will close the issue.

You can download the latest version of Aspose.Words from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards.

Hi Alexey,

I've updated this post to explain a 2nd possibly related issue!

Would you be able to try converting my attached DOCX document to PDF using the latest version of Aspose.Words? I am experiencing (2) page numbering issues, as well. However, I believe they are related.

Issue 1: Please note the page numbers 6, 7, and 8 in the DOCX compared to the page numbers 6, 8, and 9 in the PDF. For some reason when I'm converting the resulting PDF document has skipped the number 7, however no text or pages are missing after the conversion.

Issue 2: Please note the last two pages of the converted PDF document - they are numbered 53 and 53. I wonder if this is related to the first issue. My assumption is the PDF conversion process is incrementing an internal variable to create page numbers within the document, but the last page number is defined by using a different variable - something like "total pages".

Thanks!

Chris

Hi Chris,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I tried converting your document to PDF using the latest version of Aspose.OWrds and I cannot reproduce the problem with page numbering. So please try using the latest version. As I can see you are using 6.3.0 version.

Darwin, would you please check whether your issue is also resolved?

Best regards.

Alexey,

The page numbering looks resolved, but the new version has introduced a new issue. When I try to merge two documents (TOC.docx and AppendixA.docx) into a single document (Plan.docx), extra spacing is added that messes up my formatting. My production system is actually merging about a dozen files, and I only get the problem when AppendixA.docx is included. The code I am using to merge the documents is below:

public void MergeDocs()
{
Document dDoc = new Document("TOC.docx");
Document sDoc = new Document(Program.DestDir + "AppendixA.docx");
Aspose.Words.Rendering.PdfOptions opt = new Aspose.Words.Rendering.PdfOptions();

foreach (Section sSec in sDoc.Sections)
{
if (sSec.NodeType != NodeType.HeaderFooter)
{
Section nSec = (Section)dDoc.ImportNode(sSec, true);
dDoc.Sections.Add(nSec);
}
}
dDoc.Save(Program.DestDir + "Plan.docx");
}

Thanks in advance for your assistance.

Regards,

Darwin R. Pinder, Jr.

Hi Darwin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I closed the issue with page numbering.

Code to merge two document could be much simpler than yours. Please see the following code:

Document dst = new Document(@"Test001\TOC.docx");

Document src = new Document(@"Test001\AppendixA.docx");

dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

dst.Save(@"Test001\out.docx");

Using this code, I cannot reproduce the problem with spacing. Hope this could help you.

Best regards.

Alexey,

Thank you, your code example is much more concise (simpler == better). However, I am still experiencing problems with spacing. You'll notice TOC.docx is 4 pages long, and AppendixA.docx is 2 pages long. When using your code to append AppendixA to TOC, the resultant document is 10 pages long, and not 6. I have also tried using the UseDestinationStyles enumeration value, which resulted in a 12 page document.

Thanks,

Darwin Pinder

Hi Darwin,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I missed that TOC document was changed after appending the document to it. I managed to reproduce this problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards.

The issues you have found earlier (filed as 10898) have been fixed in this update.


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

Is there some code that needs to be added to split the page numbering per original document? I’m getting the page x of (total of all merged pages) no matter if I save in docx or pdf, and using the latest version of Words

I’m using the Page and NumPages fields in the header, maybe that isn’t correct?


Thanks,
Mirek

Hi Mirek,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please attach your input documents and sample code, which will allow me to reproduce the problem on my side? I will check the issue and provide you more information.

Best regards.

Here is te function I use to combine documents:

‘’’


‘’’ Combine multiple templates/documents
‘’’

‘’’ List of Aspose.Words.Document
‘’’ combined document
‘’’
Function MergeDocuments(ByVal DocList As List(Of Document)) As Document

Dim basedoc As New Document

'removes blank spaces from document
basedoc.RemoveAllChildren()
Dim i As Integer = 0
For Each tmpdoc As Document In DocList


If i = 0 Then
basedoc = tmpdoc
Else
AppendDoc(basedoc, tmpdoc)
End If

i += 1
Next

Return basedoc

End Function


then just send the combined to the browser like:

DocToSend.Save(“test.pdf”, SaveFormat.Pdf, SaveType.OpenInWord, HttpContext.Current.Response)


two sample docs attached, see that one has 3 pages, one has 6 pages, instead of being numbered 1-3 and then 1-6, they are combined and numbered 1-9



Thanks in advance,
Mirek