What is the best way to create a PDF from an htmlstring? What we are seeing is it create the pdf, but as an image, which is causing the file size to be very large. Is there a way to use the method below but not have it create as an image? We are currently doing this:
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageSettings setting = new PdfPageSettings();
setting.Size = new SizeF(595, 842);
setting.Margins = new Spire.Pdf.Graphics.PdfMargins(60);
Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat htmlLayoutFormat = new Spire.Pdf.HtmlConverter.PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = true;
htmlLayoutFormat.Layout = PdfLayoutType.Paginate;
Thread thread = new Thread(() =>
{
doc.LoadFromHTML(htmlString, true, setting, htmlLayoutFormat);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save pdf file.
doc.SaveToFile(filePath);
Also is there a way to add css styling when generating a pdf via a html string? I have been unable to find anything to do that.