Hello,
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))
{
_stopWatchSteps.Stop();
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?
Thanks,
Sheri