Hi,
I keep getting an error what ever I do, while trying to convert an html page.
The code I am using on my web project is:
PdfDocument pdf = new PdfDocument();
pdf.PageSettings.SetMargins(0);
pdf.PageSettings.Orientation = PdfPageOrientation.Portrait;
pdf.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0;
PdfPage page = pdf.Pages.Add();
PdfUnitConvertor converter = new PdfUnitConvertor();
float width = converter.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
try
{
using (HtmlConverter html = new HtmlConverter())
{
html.EnableJavaScript = true;
html.AutoDetectPageBreak = true;
html.EnableHyperlinks = true;
HtmlToPdfResult result = html.Convert("http://www.syncfusion.com", ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth);
if (result != null)
{
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
mf.Quality = 100;
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
pdf.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = true;
result.Render(page, format);
}
else
{
Response.Write("Warning! Please check the HTML link");
}
pdf.Save("Sample.pdf", Response, HttpReadType.Save);
}
}
catch (Exception exeption)
{
string message = exeption.Message;
Response.Write(exeption);
}
I did reference Syncfusion.HTML.Convert.Base and Syncfusion.HTML.Pdf.Base
And this an error I am getting.
System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. at System.Windows.Forms.AxHost..ctor(String clsid, Int32 flags) at Syncfusion.HtmlConverter.Natives.AxWebBrowser..ctor() at Syncfusion.HtmlConverter.HtmlConverter.InitializeControl() at Syncfusion.HtmlConverter.HtmlConverter..ctor()
Am I missing anything?
Thank you in advance for your attention.