I want to Convert html to pdf as a memory stream on Azure. My solution works fine on local, but when I run on azure I get the follwoing error
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
at System.Windows.Forms.UnsafeNativeMethods+IWebBrowser2.Navigate2(System.Object ByRef, System.Object ByRef, System.Object ByRef, System.Object ByRef, System.Object ByRef)
at System.Windows.Forms.WebBrowser.PerformNavigate2(System.Object ByRef, System.Object ByRef, System.Object ByRef, System.Object ByRef, System.Object ByRef)
at System.Windows.Forms.WebBrowser.PerformNavigateHelper(System.String, Boolean, System.String, Byte[], System.String)
at System.Windows.Forms.WebBrowser.Navigate(System.String, Boolean)
at Spire.Pdf.HtmlConverter.HtmlConverter.ᜆ()
example of my code
- Code: Select all
private MemoryStream GetPDFStream(string data, string type)
{
Thread thread;
if (type == "html")
{
// Html to Pdf
thread = new Thread(() => { doc.LoadFromHTML(data, false, setting, htmlLayoutFormat); });
}
else
{
// Url to Pdf
thread = new Thread(() => { doc.LoadFromHTML(data, true, true, true, setting, htmlLayoutFormat); });
}
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
MemoryStream tostrem = new MemoryStream();
doc.SaveToStream(tostrem);
return tostrem;
}
I have also looked at the new plugin that I have seen suggested on other posts, but this seems to save to file, not to a memory stream, unless I am missing something.