Good morning!
i am looking for HTML to PDF conversion without plugin.
Spire PDF version : 10.7.21
Followed below sample, which is download from your sample code
- Code: Select all
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
using System.IO;
using System.Threading;
using System.Drawing;
namespace ConvertHtmlStringToPdfWithoutPlugin
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Create a PdfPageSettings object
PdfPageSettings setting = new PdfPageSettings();
//Save page size and margins through the object
setting.Size = new SizeF(1000, 1000);
setting.Margins = new Spire.Pdf.Graphics.PdfMargins(20);
//Create a PdfHtmlLayoutFormat object
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
//Set IsWaiting property to true
htmlLayoutFormat.IsWaiting = true;
//Read html string from a .html file
string htmlString = File.ReadAllText(@"C:\Users\Administrator\Desktop\Document\Html\Sample.html");
//Load HTML from html string using LoadFromHTML method
Thread thread = new Thread(() =>
{ doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save to a PDF file
doc.SaveToFile("HtmlStringToPdf.pdf");
}
}
}
Getting below erros
using Spire.Pdf.HtmlConverter; - namespace Htmlconverter not fould
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat(); - PDFHTMLLayoutFormat could not be found
doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat); - LoadFromHtml could not be found
Here I have attached console app.
Could you please check and help us
Thanks
kannan