Merge documents with same pages

Hi,

I need to merge two documents with their own pages, like please find my attachment having 5 pages with two orientations. The last page itself is a different document having its own header and page orientation but footer was common to entire document after merging. Could you please suggest me on this how to this?

Thanks,

Hi

Thanks for your request. In footers of both sections in your document you have PAGE and NUMPAGES fields. MS Word updates these fields automatically, when you open your document.
You can try setting RestartPageNumbering property:
https://reference.aspose.com/words/net/aspose.words/pagesetup/restartpagenumbering/
Hope this helps.
Best regards.

Hi Alexey,

Thanks for your response, my intention was combining two documents where one document having page orientation as Landscape and other on is normal document, So i need to combine these two documents where starting pages should have normal document and last pages have Landscape document as my document attached earlier. Let suppose,

Document doc1 = new document();
doc1builder1.Writeln("first line");

Document doc2 = new document();

doc2builder2.PageSetup.ClearFormatting();
doc2builder2.InsertBreak(BreakType.SectionBreakNewPage);
doc2builder2.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
doc2builder2.PageSetup.VerticalAlignment = PageVerticalAlignment.Center;
doc2builder2.Writeln("second line.");

So now i need to combine these doc1 and doc2, the output document should have doc1 pages are starting pages and doc2 pages are last pages.

Could you please suggest on this?

Thanks,

Hi

Thanks for your inquiry. You can use Document.AppendDocument method to achieve this. Please see the following code:

// Open source and destination documents.
Document dst = new Document(@"Test001\dst.doc");
Document src = new Document(@"Test001\src.doc");
dst.AppendDocument(src, ImportFormatMode.UseDestinationStyles);
dst.Save(@"Test001\out.doc");

Hope this helps.
Best regards.

Hi Alexey,

Thanks for your response,

Some times i am getting this error, when i am using above code:

Item has already been added. Key in dictionary: ‘DocumentName1’
Key being added: ‘DocumentName1’ at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key,
Object value) at ᰗ.ᢋ.ᰨ(Int32 ᡴ, String ހ, Int32 ֧) at ᰗ.ᢋ.ᰢ(ᢋ ږ, Int32 ᰣ) at
㋟.㌚.㌥() at ㋟.㋞.㋵() at ㋟.㋞.〈(⍝ 〉) at Aspose.Words.Document.ԅ(Stream Ӿ, String Ӽ,
SaveFormat Ԇ) at Aspose.Words.Document.Save(String fileName, SaveFormat
fileFormat) at Aspose.Words.Document.Save(String fileName)

Shall i know why this was happening and how to overcome this one?

Thanks,

Hi

Thanks for your request. Which version of Asopose.Words do you use for testing? To check version of the library, right click on the dll, select Properties from the context menu, then select Version tab. You will see File version.
Could you please also provide me sample documents and code, which will allow me to reproduce the problem on my side?
Best regards.

HI Alexey,

Thanks for your response, i am using latest Aspose.Words 7.0.0.0 and here is the code and sample docs where i am getting the problem.

Document dst = new Document(@"D:\Final\src1.doc");
Document src = new Document(@"D:\Final\src2.doc");
dst.AppendDocument(src, ImportFormatMode.UseDestinationStyles);
dst.Save(@"D:\Final\Final.doc");

Thanks,

Hi

Thank you for additional information. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
The problem occurs because your destination and source documents contain bookmarks with the same name. As a workaround, you can try removing bookmarks before appending a document.
Best regards.

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

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