MinorFormattingLoss when converting a Docx to pdf

I am getting below error when trying to convert a docx to pdf:
Warning: MinorFormattingLoss
Source: Docx
Description: Import of element ‘numId’ is not supported in Docx format by Aspose.Words.
My code are as follows and the file is attached:

private MemoryStream ConvertWordToPdf(MemoryStream inputFileStream)
{
    inputFileStream.Position = 0; // Ensure the input stream is at the start
    _asposeGlobalMetered.Words.CheckLicense();
    var opts = new LoadOptions()
    {
        WarningCallback = new WarningCallback(),
        FontSettings = new FontSettings()
        {
            SubstitutionSettings =
            {
                FontConfigSubstitution =
                {
                    Enabled = true
                }
            }
        },
        LoadFormat = AsposeWords.LoadFormat.Docx
    };
    AsposeWords.Document doc = new AsposeWords.Document(inputFileStream,opts);
    var outputStream = new MemoryStream();
    doc.Save(outputStream, AsposeWords.SaveFormat.Pdf);
    return outputStream;

}

If I remove the header from the file, it works fine.

Any help.
BeOneImportSubdomain.docx (23.0 KB)

@abhiramsurrun This is not an error, this is a warning. Aspose.Words just let you know that there might be a minor formatting loss. But in your case, as I can see, the document is rendered fine and the output looks the same as PDF produce by MS Word. So you can safely ignore the warning.

I managed to get the exact error by implementing the IWarningCallback class.
Should I clear the warning in the WarningCallBack class I implemented?
Currently it fails on line:

AsposeWords.Document doc = new AsposeWords.Document(inputFileStream,opts);

With error:

An error occurred processing file \\...........\BeOneImportSubdomain.docx: Aspose.Words.FileCorruptedException: The document appears to be corrupted and cannot be loaded.
       ---> System.ArgumentException: This style is not a character style.
         at Aspose.Words.Font.set_Style(Style value)
         at w.d(Object d)
         at w.d(MethodBase d, Boolean v)
         at w.M()
         at w.Y(Boolean d)
         at w.d(Object d)
         at w.O()
         at w.d(Object d, UInt32 v)
         at w.Y(Boolean d)
         at w.d(Object[] d, Type[] v, Type[] c, Object[] t)
         at w.d(Int32 d, Type[] v, Type[] c, Boolean t)
         at w.e(w d, B v)
         at w.M()
         at w.Y(Boolean d)
         at w.d(Object d)
         at w.O()
         at w.d(Object d, UInt32 v)
         at w.Y(Boolean d)
         at w.d(Object[] d, Type[] v, Type[] c, Object[] t)
         at MCi.d(Document d)
         at MCi.VisitDocumentEnd(Document d)
         at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
         at MCi.d(Document d, LoadOptions v, LoadFormat c)
         at w.d(Object d)
         at w.d(MethodBase d, Boolean v)
         at w.M()
         at w.Y(Boolean d)
         at w.d(Object d)
         at w.O()
         at w.d(Object d, UInt32 v)
         at w.Y(Boolean d)
         at w.d(Object[] d, Type[] v, Type[] c, Object[] t)
         at Aspose.Words.Document.v(LoadOptions d)
         at Aspose.Words.Document.v(Stream d, LoadOptions v)
         --- End of inner exception stack trace ---
         at Aspose.Words.Document.v(Stream d, LoadOptions v)
         at Aspose.Words.Document..ctor(Stream stream, LoadOptions loadOptions)

@abhiramsurrun FileCorruptedException is not related the warning. FileCorruptedException is thrown by Aspose.Words when it cannot load the document, for example, if the file is damaged. I cannot reproduce the problem on my side. I can successfully convert your document to PDF using the latest 24.11 version of Aspose.Words and the following simple code:"

Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");

Thanks for your response @alexey.noskov but when I tried same on my laptop with Aspose.Words version 24.11, it still fails with the corrupt error, have attached a screenshot:

var doc = new Document(@“C:\dev\MyPath\BeOneImportSubdomain.docx”);

BeOneImportSubdomain.docx (23.0 KB)

@abhiramsurrun Unfortunately, I still cannot reproduce the problem on my side. Could you lease create a simple console application that will allow us to reproduce the problem and attach it here?

As advised, I created a simple console application which read the file using Aspose Words version 24.11 (The error can be reproduce via the exe)

But I cannot upload it here as I get the file too big error even though the Zip is only 26MB
I have shared it via my google drive:
https://drive.google.com/file/d/1crJsQew6jInPNVdxb1wDOgwO5qL-giI-/view?usp=sharing

@abhiramsurrun Thank you for additional information. But I mean the project, not the compiled application. Could you please zip and attach the whole project of this console application.

Sure, attached is the zip of the project.
AsposeIssueConsoleApp.zip (145.7 KB)

@abhiramsurrun Thank you for additional information. The problem is reproducible only in evaluation mode, i.e. without the license applied.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27657

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

So to fix the problem on your side you should simply apply Aspose.Words license:
https://docs.aspose.com/words/net/licensing/

Hi @alexey.noskov , we do have a license. I added it and the error changed to:

HResult=0x80131500
Message=Incorrect file header
Source=Aspose.PDF
StackTrace:
at #=zAFZhrBStm7AHCz0VQEX7Oy5om_xavbqaUA==.#=zBagE0r4ObpDB()
at #=zAFZhrBStm7AHCz0VQEX7Oy5om_xavbqaUA==…ctor(Stream #=zTx8$hZ0=, String #=zcjQ9zqo=, Boolean #=ztk0mEHeUnU10)
at #=zAFZhrBStm7AHCz0VQEX7Oy5om_xavbqaUA==…ctor(String #=zrBlPjm4=)
at #=zsEWxhfRwdVf1djN$MD3NVVbqKcMt…ctor(String #=zrBlPjm4=)
at Aspose.Pdf.Document.#=zg7v4BUE=(String #=zrBlPjm4=, String #=zcjQ9zqo=)
at Aspose.Pdf.Document…ctor(String filename)

Seems the error is with the header in the docx file.

@abhiramsurrun As I can see the error is from Aspose.PDF, not from Aspose.Words. Do you use Aspose.PDF for postprocessing PDF documents produced by Aspose.Words?

It works fine now with the license enabled, I had to explicitly use “AsposeWords.Document” instead of “Document”:

private MemoryStream ConvertWordToPdf(MemoryStream inputFileStream)
{
    inputFileStream.Position = 0; // Ensure the input stream is at the start
    _asposeGlobalMetered.Words.CheckLicense();
    var opts = new LoadOptions()
    {
        WarningCallback = new WarningCallback(),
        LoadFormat = AsposeWords.LoadFormat.Docx
    };
    AsposeWords.Document doc = new AsposeWords.Document(inputFileStream,opts);
    var outputStream = new MemoryStream();
    doc.Save(outputStream, AsposeWords.SaveFormat.Pdf);
    return outputStream;

}

Thank you very much for your help and guidance.

1 Like