Formatting corrupt and styles lost after using AppendDocument

Last post 02-20-2009, 5:44 PM by alexey.noskov. 1 replies.
Sort Posts: Previous Next
  •  02-19-2009, 5:07 PM 166103

    Formatting corrupt and styles lost after using AppendDocument

    Attachment: Present (inaccessible)

    We are using the latest build of Aspose.Words downloaded just last week. We have very simple code below that combines 2 documents together from memory and are performing this 3 times to create a single document from 4 seperate DOCX files. The output is nothing like the output we get when using MS Word automation, which correctly appends each document with page breaks and does not insert extra spacing or overwrite default styles for each document, rather merges and renames or embeds them appropriately.

    With Aspose.Words, it appears after appending these 4 documents we get an unexpected outcome (see attached). The GUID file name, "26fa68c4336644fb8dec41737919f762.docx" is the final output of appending the 4 documents.

    Thanks,
    Chad

    public static MemoryStream CombineDocuments(MemoryStream msDstDoc, MemoryStream msSrcDoc)
    {
       msDstDoc.Position = 0;
       AW.Document dstDoc =
    new AW.Document((Stream)msDstDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
       msSrcDoc.Position = 0;
       AW.Document srcDoc =
    new AW.Document((Stream)msSrcDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
       dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
       MemoryStream ms = new MemoryStream();
       dstDoc.Save((
    Stream)ms, Aspose.Words.SaveFormat.Docx);
       return ms;
    }

     
  •  02-20-2009, 5:44 PM 166286 in reply to 166103

    Re: Formatting corrupt and styles lost after using AppendDocument

    Hi

     

    Thanks for your request and sorry for delayed response. I managed to reproduce the problem and created new issue #7603 in our defect database.

    The problem occurs because “No Spacing” style from “Cigna_CHCP - Employee.docx” is copied to destinations document not properly for some reason. As a workaround you can try using the following code:

     

    public MemoryStream CombineDocuments(MemoryStream msDstDoc, MemoryStream msSrcDoc)

    {

        msDstDoc.Position = 0;

        Document dstDoc = new Document((Stream)msDstDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);

        msSrcDoc.Position = 0;

        Document srcDoc = new Document((Stream)msSrcDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);

        dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.UseDestinationStyles);

        MemoryStream ms = new MemoryStream();

        dstDoc.Save((Stream)ms, Aspose.Words.SaveFormat.Docx);

        return ms;

    }

     

    However this will not fully solve the problem, because first (Eligibility_EE.docx) and second (Cigna_CHCP - Employee.docx) documents contains style “No Spacing”. However, formatting defined in this style is different in first and second document. In the first document font size is 11, and in the second 10.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML