Exception converting HTM and MHT to PDF


I am testing Aspose.HTML .NET 18.5.0 and converting the HTML files into PDF.

When trying to convert an HTM that I created using the Settings Cog -> File->Save As option in IE, I get the following exception.

Message: Exception thrown creating Aspose HTML Document for IE Save As PEERNET HOME.htm: System.InvalidOperationException: Operation is not valid due to the current state of the object.

When trying to convert an MHT that I created the same way, I get the following exception:

Message: Exception thrown creating Aspose HTML Document for IE PEERNET HOME.mht: System.InvalidCastException: Unable to cast object of type ‘Aspose.Html.Dom.Element’ to type ‘Aspose.Html.HTMLHtmlElement’.

This is my code:

// Create HtmlDocument instance while passing path of already created HTML file
using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(FILE_PATH))
    TestContext.WriteLine("Time to Open: " + _stopWatchSteps.Elapsed.ToString());

    Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
    pdf_options.PageSetup.AdjustToWidestPage = true;

    // Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments
    using (Aspose.Html.Rendering.Pdf.PdfDevice pdf_device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, OUTPUT_DIR + OUTPUT_NAME))
        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
            // Render the output using HtmlRenderer
            renderer.Render(pdf_device, html_document);

Sample files: IE Save As PEERNET HOME.zip (1.6 MB)

Can these types of files be converted to PDF?




Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. Below tickets have been logged in our issue management system for further investigation and resolution.

  • HTMLNET-1266: Problem rendering HTM file
  • HTMLNET-1267: Problem rendering MHT file

The ticket IDs have been linked with this thread so that you will receive notifications as soon as the tickets are resolved. We will be sharing our findings with you once these issues are investigated in our environment.

We are sorry for the inconvenience.

The issues you have found earlier (filed as HTMLNET-1267,HTMLNET-1266) have been fixed in this update.