Convert MHTML to PDF in C# using Aspose.PDF for .NET - max-width attribute is creating issue

Hi

i have a MHTML (sample attached, btw generated by Aspose-EMail) and i want to convert to PDF.
i do:
Aspose.Pdf.Document pdfDoc= new Aspose.Pdf.Document(mhtStream, new Aspose.Pdf.MhtLoadOptions());
pdfDoc.Save(“outp2.pdf”);

Line 1 throws an exception: “min (56562) > opt (0)”

I have no idea, what to do…

ulimht-tmpfile.zip (7.1 KB)

@uboddenberg

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. A ticket with ID PDFNET-46451 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Hello,

I am having the same exact issue when trying to render an html document to a pdf. I cannot find any issues or similar experiences online except for this one, is there any update on why this error keeps happening? I am trying to render html tables that I generate as pdfs and most of them work, but for some reason I keep getting several ones that will not render and will throw this exception, each time with a different value in the min parameter. Is there any insight on why this might be happening?

Thank you,
Zachary

@zach25724

Regretfully there are no updates yet regarding issue resolution. We have recorded your concerns and will surely keep you informed on the status of issue rectification. Please spare us some time.

We are sorry for the inconvenience.

Hello,

Thank you for the quick response. I did find a work around but I don’t think it is exactly a fix. I compared a few of the tables that were not rendering, each one would throw that exception. When stepping through my code and stopping at the breakpoint that captures my web page’s html, I noticed that the XML view of that string is breaking at the same point for each, the max-width attribute. When the data grids are generated on our application’s side, for some reason they are generated with a tfoot element and each of those has a style of max-width:0; I have removed these from the string and the html document is now being rendered as a pdf and saving correctly. I’m not sure if this will help much but from my end it seems like the pdf rendering functionality does not like that attribute for some reason. Here is a clip of my source code for reference:

// Using WebClient, get the html of the Url.
string html;
using (WebClient client = new WebClient())
{
client.UseDefaultCredentials = true;
html = client.DownloadString(currentUrl).Replace(“max-width:0;”, “max-width:none;”);
}

            // Configure the Aspose PDF rendering options.
            renderOptions = GetPdfRenderOptions(1500, 1500);

            // 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(renderOptions, fileName))
            {
                // Create HtmlRenderer object
                using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                {
                    // Create Aspose HTML document object from generated URL of grid. 
                    using (Aspose.Html.HTMLDocument htmlDoc = new Aspose.Html.HTMLDocument(html, currentUrl))
                    {
                        // Render to PDF device, saving the PDF to file for PNG conversion. 
                        renderer.Render(pdf_device, htmlDoc);
                    }
                }
            }

Thank you,
Zachary

@zach25724

Thanks for sharing these details.

This workaround would definitely be helpful during investigation and resolution of the logged issue. We will surely post additional updates within this forum thread as soon as we have some.

The issues you have found earlier (filed as PDFNET-46451) have been fixed in Aspose.PDF for .NET 21.12.