We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word Document to PDF "Attempted to divide by zero"

Hi There

I am trying to combine multiple documents into 1 single PDF. The files that I attempt to combine is a combination of Word Documents and HTML files. Till date, is has been running in Production without any issues but for some reason, in certain cases, I get a “Attempted to divide by zero” error when trying to save my “Document” class as PDF. I have boiled the issue down to one HTML file that is causing this issue, but the error occurs withing the Aspose.Words library and is not my code that is causing this.

I first convert any HTML files to Word format:

using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(fileName)))
{
     Document htmlDoc = new Document(stream, new HtmlLoadOptions
     {
         LoadFormat = LoadFormat.Html
     });

     htmlDoc.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2013);

     using (MemoryStream wordDocStream = new MemoryStream())
     {
         htmlDoc.Save(wordDocStream, new OoxmlSaveOptions(SaveFormat.Docx) { Compliance = OoxmlCompliance.Iso29500_2008_Transitional });

         return new Document(wordDocStream);
     }
}

I combine all the document by making use of the “AppendDocument” function:

finalDocument.AppendDocument(document, ImportFormatMode.UseDestinationStyles);

Finally, I save “finalDocument” as PDF (this is where I get the error):

MemoryStream pdfStream = new MemoryStream();

doc.Save(pdfStream, new PdfSaveOptions
{
    SaveFormat = SaveFormat.Pdf
});
return pdfStream;

BulkPDFConverter.zip (38.8 KB)

I have attached an example Console Application (running netcore 2.2), along with an example of an HTML file that is causing this error. Please can you investigate what is causing this “Attempted to divide by zero” error since this issue happens within the Aspose.Words library.

Thank you in advance.

@RuanVM,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19549. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hi @awais.hafeez

Is there any feedback on this issue? This issue is causing a lot of complaints by our clients. Is there anywhere I can track the status of the logged issue?

@RuanVM,

I am afraid, your issue (WORDSNET-19549) is currently ‘pending for analysis’ and is in the queue. We will inform you via this thread as soon as this issue will be resolved in future. We apologize for your inconvenience.

Unfortunately, there is no direct way that you can use to track issues by yourself. But, you are welcome to ask your issue status via forum threads. We will verify the status from our internal issue tracking system and then reply you back.

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