Invalid .docx File Signature using Aspose.Words for .NET

Hello,

I am using Aspose.Total 18.12 within an application to generate PDFs and Word files that are share with a third party service. When creating a very simple Proof of Concept document similar to outlined in your online documentation but also ensuring the document contains the minimum amount of info.

The client that I am interfacing with ensures document integrity by checking the file signature (by parsing the first file bytes of the file). Their system is rejecting the document created by Word due to it not conforming to the .docx file signature.

For example:
I create a document using aspose with the code below, the file signature is:
50 4B 03 04 14 00 00
If I open that same document using word, and select “Save As” it will then change the file signature to:
50 4B 03 04 14 06 00

Is there a way around this? Can I force Aspose.Words to save with the correct 8 byte file signature for docx? Currently this conforms to the 4 byte file signature for docx but unfortunately that is not strong enough for the service we are interfacing with.

Code to generate Document:

private static void CreateBlankDocument(string filePath = null)
        {
            var document = new Document();
            document.EnsureMinimum();

            var newFileName = $"Blank_Document{DateTime.Now.ToLongTimeString()}".Replace(':', '-').Replace(" ", "");

            document.Save($"C:\\TEMP\\{newFileName}.docx");
        }

Note: I have tried using different options like ".OptimizeFor(…Word2016) but that does not seem to affect the file signature

Attachments.zip (88.9 KB)

@dsiebert

Could you please share some detail how are you checking file signature?

If you unzip both files created by Aspose.Words and MS Word, there is no issue with them. Could you please share complete detail about your requirement in which scenario you need this file signature? We will then provide you more information about your query.

Hi Tahir,

I am using a product called vbindiff which is a visual tool for compare the binary bytes of two files. If you look at the binary bytes of a file there should always be some values pre-pended to the start of the data that indicate the file type, so in this case we would be expecting values outlined in for .docx listed on this website:
https://www.filesignatures.net/index.php?page=search&search=DOCX&mode=EXT

However, when I use an inspector to look at my document generated by aspose it does not have the correct file signature for an 8-byte signature (which is the expected signature for word files that are 2007+).

As you can see from the screenshot that I attached in the .zip named ‘visualByteDiff.png’ the 7th byte in the file signature should be 06, however aspose generates this value to be 00.

While Word365 can open both of these files its likely due to a compatibility mode that allows word to open older files with a more broad spectrum of file signatures. What I would like to know is if there is a way to generate a file using Aspose that conforms to the Word 2007+ format with 8 byte file signature.

Note: I have tried using the .OptimizeFor(.Word2007) and .OptimizeFor(.Word2016) methods on the Document which do not change the file signature.

@dsiebert

We suggest you please use the latest version of Aspose.Words for .NET 20.3 with following code example. Hope this helps you.

Document doc = new Document(MyDir  + "in.docx");
                
OoxmlSaveOptions options = new OoxmlSaveOptions();
options.Compliance = OoxmlCompliance.Iso29500_2008_Strict;

doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2019);
doc.Save(MyDir + "20.3.docx", options);

Please let us know if you still face problem.

Hello Tahir,

Can you please generate a document in this way and attach it to your response so I may verify that this resolves the problem? Our existing product heavily utilizes 18.12 and we would prefer ensure that this solution will work prior investing in the newer product financially as well as going through a full regression by integrating it.

p.s. I have tried setting the compliance to Iso29500_2008_Strict; and this still produces the same result, where the 7th byte in the file signature is set to “00” instead of the expected “06”.

Thank you!

@dsiebert

Please check the attached Word document and let us know about your findings. 20.3.zip (5.3 KB)

Hello Tahir,

This did not solve the issue we are seeing. The 7th byte of the file signature still reads “00” from the Aspose Generated document from Version 20.3 that you have provided. Here is an image of the diff between the file and the same file “Saved As” from Word 2016.

2020-03-20 07_44_50-Command Prompt - vbindiff 20.3.docx SaveAsFromWord2016.docx.png (34.8 KB)

Do you have any other possible solutions?

@dsiebert

We have logged this problem in our issue tracking system as WORDSNET-20169. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-20169) have been fixed in this Aspose.Words for .NET 20.5 update and this Aspose.Words for Java 20.5 update.