Page Numbers while Murging the Multiple Word Documents

I have around 100 word documents to murge into 1 doc (Like this i have 4 sets , 400 doc to be murged into 4 doc with each 100 doc) and each doc has different number of pages and i want to retain the page number as is like

1. If First Doc has 20 pages then page should be 1 of 20,2 of 20....20 of 20

2.If Second Doc has 30 pages then page should be 1 of 30, 2 of 30 ....30 of 30.

We know if we use NUMPAGES then it will sum up all the pages.

I implemenetd this in two ways:

1. By following http://www.aspose.com/docs/display/wordsnet/Controlling+How+Page+Numbering+is+Handled

this URL and implemented in Java, but as i have 100 docs to append it is in infinite loop and i waited for 2 hours and no luck. This works fine if i have less than 25 documents to murge and it took 10 min. Do we have any solutions here? I am using version 15.

2. I removed NUMPAGES and added some plain text and replaced this with the page count on each doc and then merged. I had some luck here but in few documents page count is incorrect and it is adding +1 to the actual size. When i looked into those specific documents it has one table which has spread across multiple pages and looks like it is creating problem. I do have other tables in other section of page and it is fine. Unfortunatelly i wont be able to share the Template, any guess what might be going wrong with that table?

Document doc = new Document(pdfFilePath);

doc.updatePageLayout()

doc.getBuiltInDocumentProperties().getPages()

I appriciate your help and eagerly waiting for your Help!.

Thanks,

Praveen Gowda

I tryed even

doc.getPageCount() But same result

Hi Praveen,

Thanks for your inquiry. In your case, I suggest you following solution.

1) Please remove all section breaks from your document. You document should contain one section.
2) In case, your input document have section break (new page), please replace it with page break.
3) Please replace NUMPAGES field with SECTIONPAGES field.

Please read following documentation link for your kind reference. Hope this helps you.
http://www.aspose.com/docs/display/wordsjava/How+to++Remove+Page+and+Section+Breaks

Thanks a lot Tahir.

This is working fine and page Number count is accurate as well in each doc and even after merging.

As a Followup question i have difficulties in displaying MergeField value in the IF condition. I need to display MergeField value when we are in page 2 in the footer but the MergeField is displayed as text insted of displaying the value as we need to place the MergeField in the "". Do you have any examples for this.

Thanks

Praveen

Hi Praveen,

Thanks for your inquiry. I suggest you please read about executing simple mail merge from here:
http://www.aspose.com/docs/display/wordsjava/How+to++Execute+Simple+Mail+Merge

If you still face problem, please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please

    create a standalone/runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.