Adding new header / footer to a .docx doucument with SDK for Open XML Formats RRS feed

  • Question


    Is it possible to have more than one set of header / footer elements in a .docx document.  I ask because I have seen a few examlpes of merging the MainDocument section of two .docx document's but not any with headers, footers, etc.  What I need is to combine multiple .docx files for a print project.  The user would have selected a list of documents they wanted printed from a web browser.  Once selected and the user presses print in the web form the doucments will be spit out as a byte[] to a response stream and printed through the browser.  I was thinking of trying to merge all of the .docx documents together so you would only get one print dialog prompt rather than 20 if a user was printing 20 .docx document's.  The .docx documents are being used as templates with prefilled data.  The header, footers, etc. will be different from document to document which inclines me to think this is not possible but if it is that would be great.  Does anybody have any experience / thoughts on the idea?


    Thanks for thoughts!!



    Wednesday, November 14, 2007 8:04 PM

All replies


    Yes, it is possible (theoretically) to have several headers/footers making separate "sections" (one section for one pair header-footer). See menu "Page layout/Breaks/Section Breaks" in MS Word 2007.


    But merging two docx is more difficult task than you describe.

    1.You can copy all parts from one docx to another (with SDK).

    2.You can copy fragments of document.xml from one docx to another (with Xml-processor).

    But you must merge another features as styles (styles.xml), numbering styles (numbering.xml), headers/footers etc. And you have to own and to implement Open Xml standard concerning all these points. But Open Xml documentation is about 5000 pages(!)


    I think that Open Xml is only applicable for generating new documents and may be for filtering some documents content. We need more functionality in next SDK releases, especially for the processing/merging/validating existing documents.


    Best wishes!


    P.S. At the moment I develop a documents processor that generates docx from fragments stored in several docx-s. Merging is the core functionality for this kind of tasks. And unfortunately there is no guaranteed solution in the community.

    Monday, November 19, 2007 6:27 PM
  • I have one more idea.


    You could generate a summary docx-document that will just refer on needed documents:


    <w:subDoc r:id="rId111" />
    <w:subDoc r:id="rId222" />
    <w:subDoc r:id="rId333" />





    document.xml.rels" Target="sub/sub1.docx" TargetMode="Internal"/>" Target="sub/sub2.docx" TargetMode="Internal"/>




    Your source files can be stored directly inside of Summary.docx 








    There are some difficulty when your user has to open/view/edit that document but it should be acceptable for printing.


    Best wishes,


    Monday, November 19, 2007 6:54 PM