Convert HTML string to PDF throws exception

I have a valid html string that I generated to .html file and viewed in the browser. the code is as follows:

        string htmlStr = "<html>" +
            "               <head> " +
            "                   <meta charset='utf-8'/>" +
            "                   <meta name='viewport' content='width=device-width, initial-scale=1.0' />" +
            "               </head> " +
            "               <body style=\"width:1001px;height:600px;margin-left:auto;margin-right:auto;\">" +
            "                   <div id='badgefront' style='width:500px;height:250px;float:left;text-align:center;font-weight:bold;font-size:20px;border-right:1px black dashed;background-color:#CCC4C0;'>" +
            "                       <p>XXXX</p>" +
            "                       <img src='..\\..\\..\\wwwroot\\data\\vme.jpg' alt='VME' height='150' width='150'> " +
            "                   </div>" +
            "                   <div id='badgeback' style='width:500px;height:250px;float:right;left;text-align:center;font-weight:bold;font-size:20px;background-color:#CCC4C0;'>" +
            "                       <p>URL: XXXXX</p> " +
    "                               <img src='..\\BarCode\\tmpBarcode-0.bmp' alt='barcode' height='125' width='400'> " +
    "                                <p>XXXXXX</p>" +
            "                   </div>" +
            "               </body>" +
            "               </html>";

After creating the string I execute the following commands:

        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
        Aspose.Pdf.HtmlFragment textFragment = new Aspose.Pdf.HtmlFragment(htmlStr);
        pdfDocument.Pages.Add();
        pdfDocument.Pages[1].Paragraphs.Add(textFragment);
        // Save output as PDF format
        pdfDocument.Save(filePath + "WebpageToPdf.pdf");

Using the ‘HtmlFragment’ I get the following error:

An exception of type ‘System.IO.FileNotFoundException’ occurred in Aspose.Pdf.dll but was not handled in user code
Could not load file or assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. The system cannot find the file specified.

If I change the ‘HtmlFragment’ to ‘TextFragment’, it will write the code to the the PDF file but not render it.

This is running in C# .Net Core 2. If you need additional information, please let me know!

Thank you,

Dustin

@DMOLDH_SANDIA_GOV

Thanks for contacting support.

We have tested the scenario using latest version i.e. Aspose.PDF for .NET 18.9 in our environment and were unable to replicate the issue. The PDF document was generated successfully and is attached as well for your reference.

WebpageToPdf.pdf (32.4 KB)

Would you please try to use latest version of the API and in case issue still persists, please share a sample console application, which is able to reproduce the issue in any environment. We will test the scenario in our environment and address it accordingly.