Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Dec 10, 2019 4:00 am

Hi,

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.

services@nvinteractive.com
 
Posts: 4
Joined: Mon Jun 18, 2018 12:50 am

Tue Dec 10, 2019 6:04 am

Hi,

Thanks for your inquiry.
On Azure, we suggest you use plugin method to convert html to PDF. Please download the newest plugin in the guide:
https://www.e-iceblue.com/Tutorials/Spi ... lugin.html
And there are overload methods in Convert method which could save to PDF stream. For example:
Code: Select all
        public static void Convert(string url, Stream stream, bool enableJavaScript, int timeout, SizeF pageSize, PdfMargins margins);


Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Dec 10, 2019 8:42 pm

Hi thanks,

I have tried the following

Code: Select all
  using (MemoryStream pdfstream = new MemoryStream())
            {
                Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(data,

                    pdfstream,

                    //enable javascript`

                    true,

                    //load timeout

                    10 * 1000,

                    //page size

                    new SizeF(612, 792),

                    //page margins

                    new Spire.Pdf.Graphics.PdfMargins(0),

                    //load from content type

                    LoadHtmlType.SourceCode

                );


But I am getting a InValidOPerationException on the memory stream

services@nvinteractive.com
 
Posts: 4
Joined: Mon Jun 18, 2018 12:50 am

Wed Dec 11, 2019 1:51 am

Hi,

To help us investigate the issue, please provide your HTML.
You could provide it here or send to us(support@e-iceblue.com) via email.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF