Free Support Forum - aspose.com

Destruction of documents with images

Hi,

i've ran some unit tests with the latest Aspose.Words .NET 11.11.0 and some failed due to an issue with the document OOXML definition. During these tests documents are created and saved to docx. Randomly the generated docx can not be opened by Word (2007 and 2013). Word is showing this error: The OOXML file cannot be opened due to issues with its content. No further details

The issue is causes by the image defintions inside the OOXML file /word/document.xml. There is this entry:

This id changes each time the docx is generated. Sometimes its become >0 and in these cases the document is correct. But it also becomes <0 randomly and in these cases the document is corrupted and can't be opened.

That issue does not occur with the previous 11.10.0 and 11.9.0 version. In these versions that id does not change. So since the new version this id seems to be generated with a critical number range.

I dont have any code to reproduce it right now as the unit tests use our integration components. If you need further details or exampled i might try to create one. But it would be great if you can reproduce it on your side yourself or locate the issue in the code.

I attach files for the different versions generated with the very same code. You see the output changes for 11.11.0 but not for the older versions.

thanks for the support,
oliver

Hi Oliver,


Thanks for your inquiry. I have checked your shared document and the output file generated with latest version of Aspose.Word can not be opened. It would be great if you please share more information about your unit testing. I will investigate the issue on my side and provide you more information.

Hi,

ok i was able to reproduce it outside of our unit tests. Heres the code:

private static void TestImageInjection(string filename, string filenameImport)
{
Document document = new Document(filename);
Document docImp = new Document(filenameImport);

Body impBody = ((Section)docImp.FirstChild).Body;

foreach(BookmarkStart nodeStart in document.GetChildNodes(NodeType.BookmarkStart, true))
{
while (impBody.HasChildNodes)
{
Node impNode = document.ImportNode(impBody.FirstChild, true);
nodeStart.ParentNode.ParentNode.AppendChild(impNode);
impBody.RemoveChild(impBody.FirstChild);
}

nodeStart.ParentNode.ParentNode.RemoveChild(nodeStart.ParentNode);
}

document.Save(filename.Replace(".docx", "_result.docx"), SaveFormat.Docx);
}

I attach the files to this post. Some information of an ETA for a fix would be highly appreciated. Maybe even a quick hotfix ?!

Thanks,
oliver

Hi Oliver,


Thanks for sharing the code. Could you please share the detail about your following function?

It seems that you are appending the contents of “txm.docx” to “template.docx”. There are two bookmarks in template.docx” and you are iterating through bookmarks and removing nodeStart.ParentNode ( what is the purposes to remove this node?). The first loop execute only once.

Please share the detail of your scenario. We will share the code with you according to your requirements.


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:blue;mso-font-kerning:
0pt;mso-no-proof:yes”>private<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> static void
TestImageInjection(string filename, string filenameImport)<o:p></o:p>

{

Document document = new Document(filename);

Document docImp = new Document(filenameImport);

Body impBody = ((Section)docImp.FirstChild).Body;

foreach (BookmarkStart nodeStart in document.GetChildNodes(NodeType.BookmarkStart, true))

{

while (impBody.HasChildNodes)

{

Node impNode = document.ImportNode(impBody.FirstChild, true);

nodeStart.ParentNode.ParentNode.AppendChild(impNode);

impBody.RemoveChild(impBody.FirstChild);

}

nodeStart.ParentNode.ParentNode.RemoveChild(nodeStart.ParentNode);

}

document.Save(filename.Replace(".docx", "_result.docx"), SaveFormat.Docx);

}

Hi tahir,

well basically i remove the bookmarks and replace them with the body content of the import document. But does it matter what and how it does when the output generated contain the issue ? In any case no matter how i use Aspose the output document should be valid and not be unusable. It were the case for the older Aspose.Words versions.

greetings and thanks,
oliver

Hi Oliver,


Thanks for the details.
oliver_zx:
well basically i remove the bookmarks and replace them with the body content of the import document.
The above code do not replace the bookmarks with body of import document. There are two bookmarks in “template.docx” so the output document should have contents of “txm.docx” twice. The above code append the import document contents at the end of “template.docx”, not at the position of bookmark.

You are removing docImp node by impBody.RemoveChild so for second bookmark there will be no nodes in impBody.

I suggest you to use the InsertDocument method share at following documentation link to insert another document contents at bookmark.
http://www.aspose.com/docs/display/wordsnet/How+to++Insert+a+Document+into+another+Document

<span style=“font-size:10.0pt;
font-family:“Courier New”;color:#2B91AF;mso-font-kerning:0pt;mso-ansi-language:
PL;mso-no-proof:yes”>
Document<span style=“font-size:10.0pt;font-family:
“Courier New”;mso-font-kerning:0pt;mso-ansi-language:PL;mso-no-proof:yes”>
mainDoc = new Document(MyDir

  • “InsertDocument1.doc”);<o:p></o:p>

Document subDoc = new Document(MyDir + "InsertDocument2.doc");

Bookmark bookmark = mainDoc.Range.Bookmarks["insertionPlace"];

InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc);

<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-font-kerning:0pt;mso-ansi-language:
EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-no-proof:yes”>mainDoc.Save(MyDir

  • “InsertDocumentAtBookmark Out.doc”);
<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-font-kerning:0pt;mso-ansi-language:
EN-GB;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-no-proof:yes”>
Moreover, if you want to use the same code, I suggest you to save the document to Doc and then re-save to Docx as shown below. I have attached the output document with this post.

<span lang=“NL” style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:0pt;mso-ansi-language:
NL;mso-no-proof:yes”>Document

<span lang=“NL” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-ansi-language:NL;mso-no-proof:
yes”> document = new Document(MyDir
  • “template.docx”);<o:p></o:p>
  • Document docImp = new Document(MyDir + "txm.docx");

    Body impBody = ((Section)docImp.FirstChild).Body;

    foreach (BookmarkStart nodeStart in document.GetChildNodes(NodeType.BookmarkStart, true))

    {

    while (impBody.HasChildNodes)

    {

    Node impNode = document.ImportNode(impBody.FirstChild, true);

    nodeStart.ParentNode.ParentNode.AppendChild(impNode);

    impBody.RemoveChild(impBody.FirstChild);

    }

    nodeStart.ParentNode.ParentNode.RemoveChild(nodeStart.ParentNode);

    }

    //document.Save(MyDir + "out.docx", SaveFormat.Docx);

    document.Save(MyDir + "out.doc");

    Document doc = new Document(MyDir + "out.doc");

    doc.Save(MyDir + "out.docx");


    Hi tahir,

    the code of the unit test does not matter. Aspose.words should simply just never generate invalid ids. The unit test just produces it. So changing the code is not a solution for me. Saving to doc just to save to docx afterwards would be just a workaround. And even a bad one performance wise.

    Please check the generation of these ids on your side.

    Thanks for your support,
    oliver

    Hi Oliver,


    Thanks for sharing the details. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-7635 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

    We apologize for your inconvenience.

    Hi Oliver,


    Thanks for your patience. We have a good news for you that is WORDSNET-7635 has now been resolved and its fix will be included in the next version of Aspose.Words (v13.1.0) which is planned to be released by the end of this month (around January’ 31, 2013). We will inform you via this forum thread as soon as the new release is published at the end of the month.

    Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

    The issues you have found earlier (filed as WORDSNET-7635) have been fixed in this .NET update and this Java update.


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