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