# Combining multiple docs into single doc programmatically



## pvrreddy (Sep 30, 2009)

We have a requirement to combine multiple word documents to single documents programmatically in Windows 2003. Please let me know how can we acheive this in steps. By chance if it is not acheivable in Windows 2003 and can acheive by latest Windows version also, please let me know the details.


----------



## pvrreddy (Sep 30, 2009)

The single document should support ToC(Table of Contents), spanning pagination, x of y footers etc.


----------



## macropod (Apr 11, 2008)

Hi pvrreddy,

Any Word document supports aTOC - all you need to do is to insert one and have some headings for it to reference. Also, I don't understand your reference to 'spanning pagination'. Aside from that, there are various issues you'll need to address including do any of the source documents have:
1. headers or footers?
2. footnotes or endnotes?
3. their own TOC
4. links to other documents tat might get included in the consolidation?
5. non-standard page sizes or orientations?
6. non-standard column arrangements?
7. userforms, formfields, bookmarks, cross-references?
where 'non-standard' means not in conformity with the document you're consolidating to. If so, you're going to have to resolve what you'll do with these. If any of the above apply and the documents concerned need case-by-case consideration, automation may not be practical.


----------



## pvrreddy (Sep 30, 2009)

Thanks for your reply. It looks like we can acheive this. I am new to Microsoft technologies. I am a J2EE person. Programatically I need to combine documents from a input server and send the combined document to the output server. Suppose my Input server contains 3 documents(1 doc(5 pages), 2 doc(9 pages), 3 doc(6 pages)). After combining the combined document should display the TOC with sections for doc 1, doc 2 & doc 3, original headers & footers, contents and pagination footer is something like 1 of 20. (20=5+9+6 pages). Please place some code in VBA or C# which helps.


----------



## macropod (Apr 11, 2008)

Hi pvrreddy,

You don't appear to have answered many of the questions I posed. What you're asking is not a trivial exercise and could become quite complicated once all those issues are taken into account.

Neither am I simply going to code this all for you. I'm quite prepared to help you work out how to go about it and to resolve any problems you run into, but you've got to invest some of your own effort into this. You could start of by doing web searches for vba code to concatenate Word files, loop through folders, etc. I know nothing of C#.


----------



## pvrreddy (Sep 30, 2009)

Hi macropod,

Thanks for your reply. I explained abt the requirement on what I am working. I thought like it will answer your questions. Now I am giving reply to your questions.

For your questions, the answers are below in *bold*.
Any Word document supports aTOC - all you need to do is to insert one and have some headings for it to reference. *Please let me know how can we insert one. The TOC what I am looking is each section represents each document and page is starting page of each doc in combined one.* Also, I don't understand your reference to 'spanning pagination'. *You can leave this.* Aside from that, there are various issues you'll need to address including do any of the source documents have:
1. headers or footers? *No*
2. footnotes or endnotes? *No*
3. their own TOC *No*
4. links to other documents tat might get included in the consolidation?*No*
5. non-standard page sizes or orientations?*Yes*
6. non-standard column arrangements?*Yes*
7. userforms, formfields, bookmarks, cross-references? *The documents contain tables, lines, images, Different font styles used, different language text etc*
where 'non-standard' means not in conformity with the document you're consolidating to. If so, you're going to have to resolve what you'll do with these. If any of the above apply and the documents concerned need case-by-case consideration, automation may not be practical. *Yes, it is bit difficult task. I got the below link to combine the documents 'http://www.experts-exchange.com/Programming/Languages/Q_21289408.html'. I am planing to build on that with the help of VBA developer.*


----------



## macropod (Apr 11, 2008)

Hi pvrreddy,

The use of non-standard page sizes/orientations and non-standard column arrangements means you will need to use 'Next Page' Section breaks before & after the place where the non-standard documents are inserted; otherwise the layout will be messed up. You may find it easiest to use 'Next Page' Section breaks to separate all the inserted document anyway, so its probably not a big issue.

The use of "Different font Styles" could be a complication, as could hard-formatting that overrides a given Style. What you're liable to find is that all the Styles will revert to whatever the underlying Style is for the document into which all the others are being merged. If you're using Word 2003 or later, and you're copying from the source documents, Word gives you the option of retaining the source formats when pasting. The alternative approach (if you're concerned about faithfully retaining the original formatting), is to rename the non-standard Style formats with unique names. Then, when pasting into the target document, you won't need to worry about preserving the original format -the Style definition will take care of that for you. The latter approach also means you don't have to worry about whether any edits you do later on will have the correct Style format for the Style being used.

Much the same consideration applies to languages. Provided you manage the Section breaks correctly, tables, lines & images shouldn't be a problem.

As for the TOC, the way this normally works is via the use of Word's Heading Styles. If your documents use these, then creating the TOC may be no more complicated than inserting a TOC field at the front of the document. If your documents don't use these, the Word help file describes an alternative approach. However, I suspect that what you're really after is an index to each inserted document. To create that, I suspect what you'll need to do is to bookmark each inserted document with a unique bookmark name and insert a set of hyperlinks to all the bookmarks at the front (or back) of the document.


----------



## pvrreddy (Sep 30, 2009)

Thank you. I will give a try to implement now.


----------

