none
Font size is altered after insertion one document into another RRS feed

  • Question

  • I have a problem with font size when I insert one document into another using altChunks. I use slightly modified code from this link to insert one document at the end of another:
    http://blog.jamesrossiter.co.uk/2010/01/18/combine-docx-word-2007-documents-with-the-microsoft-office-open-xml-sdk-2-0/

    (You can find test application at https://drive.google.com/file/d/0B-CEaN01bFt3Tm9mRnl5aG00LUE/view?usp=sharing)

    Dim doc1 As String = "doc1.docx"
            Dim doc2 As String = "doc2.docx"
            Dim myDoc As WordprocessingDocument = WordprocessingDocument.Open(doc1, True)
            Try

                'Dim altChunkId As String = "AltChunkId5″"
                Dim mainPart As MainDocumentPart = myDoc.MainDocumentPart
                Dim Chunk As AlternativeFormatImportPart = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML)
                Dim AltChunkId As String = mainPart.GetIdOfPart(Chunk)

                Dim fileStream As FileStream = File.Open(doc2, FileMode.Open)

                Chunk.FeedData(fileStream)
                Dim AltChunk = New AltChunk()

                AltChunk.Id = AltChunkId
                mainPart.Document.Body.InsertAfter(AltChunk, mainPart.Document.Body.Elements(Of Paragraph)().Last())
                mainPart.Document.Save()

            Finally
                myDoc.Close()
                myDoc.Dispose()
            End Try


    Doc2.docx has two paragraphs and the second one has size 11. But, after I put it at the end of Doc1.docx the same paragraph has 10.5 font size. I unzipped final document, and it looks correct: mentioned paragraph has size 11, so it’s probably Word specific bug, but maybe there is any walkaround?


    Monday, July 31, 2017 7:47 AM

All replies

  • Hi akstanya,

    I try to run the code on my side.

    I find that after clicking on button it is not adding the text to the document.

    document stays as it was before. there is no change.

    I suggest you to text your code on your side and let me know whether you got the same result like me.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 31, 2017 9:18 AM
    Moderator
  • Hello, Deepak!

    Thanks for your answer. Demo project works fine for me. Please ensure that 1) You have checked doc1.docx in bin/Debug folder 2) You use MS Word 2013 or later (you need it to handle AltChunk properly. Libre Office or OpenOffice doesn't work properly here)

    You can find my result document here  and picture which shows clearly what problem is here:

    https://drive.google.com/file/d/0B-CEaN01bFt3MzlydWw0WjFBdTQ/view

    https://drive.google.com/file/d/0B-CEaN01bFt3amJfTmlSMVFKN0U/view?usp=sharing

    Monday, July 31, 2017 10:56 AM
  • Hi akstanya,

     I again try to run the code and I can reproduce the issue as you mentioned above.

    other thing I find is :

    altChunk: Import Only

    One important note about altChunk – it is used only for importing content.  If you open the document using Word 2007 and save it, the newly saved document will not contain the alternative format content part, nor the altChunk markup that references it.  Word saves all imported content as paragraph (w:p) elements.  The standard requires this behavior from a conforming application.

    Reference:

    How to Use altChunk for Document Assembly

    so it looks like it is just focus on the content and import the content and not formatting.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 1, 2017 2:24 AM
    Moderator