Saving as Docx corrupts shapes

Hi,

I have a weird issue with a shape getting truncated after the document has been saved by Aspose as a DOCX.

Several of our clients, whose’ company branding has a yellow stripe along the bottom of the page, has on several occasions uploaded a docx that isn’t rendered properly when saved as a PDF or PNG.

I have reduced the docx to a bare minimum. It now only contains the stripe (Shape) which is contained inside a Group running long the bottom of the page. The below code (using aspose-words:17.9:jdk16) loads the original document, then resaves it as DOCX, DOC, and DOCX again. The PDF output the first docx resaved file has a trimmer shaped, but after the document got resaved as DOC, reloaded from the new file and then again saved as a DOCX the PDF output of the second DOCX is now correct.

import com.aspose.words.Document;
import com.aspose.words.License;

import java.io.FileInputStream;

public class DocxSavingBug {

    public static void main(String... args) {
        try {
            String dir = "C:\\temp\\aspose\\";
            new License().setLicense(new FileInputStream(dir + "Aspose.Words.lic"));
            Document doc = new Document(dir + "doc-with-footer.docx");
            doc.save(dir + "out-from-original.pdf");

            doc.save(dir + "doc-with-footer-resaved.docx");
            doc = new Document(dir + "doc-with-footer-resaved.docx");
            doc.save(dir + "out-from-resaved-docx.pdf");

            doc.save(dir + "doc-with-footer-resaved.doc");
            doc = new Document(dir + "doc-with-footer-resaved.doc");
            doc.save(dir + "out-from-resaved-doc.pdf");

            doc.save(dir + "doc-with-footer-resaved2.docx");
            doc = new Document(dir + "doc-with-footer-resaved2.docx");
            doc.save(dir + "out-from-resaved-docx2.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

See the attached zip containing all the output PDFs.
aspose.zip (39.8 KB)

It appears that saving as DOCX/OOXML corrupts something. I have tried the same with FLAT_OPC, OOXML, DOCM and all results were the same.

This saving issue results can be verified in MS Word by forcing it to re-save the shape object. Merely re-saving the Document is insufficient:

  • open the original Word Docx,
  • right-click the shape (be careful not to select the group) ,
  • select “More Layout Options …”
  • click OK (without actually having made any change)
  • then save the doc and run the code above again. The PDF output is now correct for all cases.

Please fix, as I don’t want to have to create an intermediate DOC file.

Regards,
Daniel

The intermediate save-as-doc hack can be simplified. We don’t even need to write a new doc and read it in again. A dummy save to a throw-away byte array alone appears to change the internal object structure, “fixing” the problem :

import com.aspose.words.DocSaveOptions;
import com.aspose.words.Document;
import com.aspose.words.License;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

public class DocxSavingBug {

    public static void main(String... args) {
        try {
            String dir = "C:\\temp\\aspose\\";
            new License().setLicense(new FileInputStream(dir + "Aspose.Words.lic"));
            Document doc = new Document(dir + "doc-with-footer.docx");
            doc.save(dir + "out-from-original.pdf");

            //hack: intermediate save as DOC to prevent rendering issue
            doc.save(new ByteArrayOutputStream(), new DocSaveOptions());

            doc.save(dir + "doc-with-footer-resaved.docx");
            doc = new Document(dir + "doc-with-footer-resaved.docx");
            doc.save(dir + "out-from-resaved-docx.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

aspose-hack.zip (27.0 KB)

@dcalde,

Thanks for your inquiry. We have tested the scenario and noticed the shape truncation issue in footer in resultant PDF. We have logged a ticket WORDSNET-16025 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

@dcalde,
The issues you have found earlier (filed as WORDSNET-16025) have been fixed in this Aspose.Words for .NET 17.12 update and this Aspose.Words for Java 17.12 update.
Please also check the following articles: