We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

HtmlToPdf.aspx example from WebSampleBrowser samples not work on Microsoft Azure Web Sites

Thread ID:

Created:

Updated:

Platform:

Replies:

117456 Oct 24,2014 09:38 AM UTC Aug 18,2016 01:19 PM UTC ASP.NET Web Forms (Classic) 7
loading
Tags: PDF
Milen Stefanov
Asked On October 24, 2014 09:38 AM UTC

We have issue related to the one which I'm creating here. I just downloaded Syncfusion EssentialStudio and run the web samples (12.2.0.36). On the local machine the HtmlToPdf.aspx work fine, but when I publish it on Azure Web Sites I get reference exception. I used the remote debugging and on line 140:

HtmlToPdfResult result = html.Convert(this.TextBox1.Text, ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth);

I get:
Could not load file or assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

After I add it to my references and set to copy local I get another exception:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Syncfusion.HtmlConverter.Base.dll Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

Please can you provide a working sample/solution for Microsoft Azure Web Sites. We have similar problem on our project which is using Syncfusion for pdf generation and there we have the same issue when we tried to migrate to Azure Web Sites.

Sample project: http://asp.syncfusion.com/demos/reporting/Pdf/Import%20and%20Export/HtmlToPdf/CS/Default.aspx
Working Enviroment: http://azure.microsoft.com/en-us/services/websites/

KarthikeyanC [Syncfusion]
Replied On October 27, 2014 05:23 AM UTC

Hi Milen,

Thank you for your interest in Syncfusion Products.

 

Our Html Converter makes use of MSHTML(IE Rendering Engine) to convert HTML to Image and then the Image is converted to PDF. As Microsoft.mshtml.dll assembly is not present in Azure cloud this issue occurs. Please refer this assembly in your project and copy the assemblies to local to get this issue fixed.

 

    <Reference Include="Microsoft.mshtml">

      <Private>True</Private>

    </Reference>

 

Thanks,

Karthikeyan.C


Milen Stefanov
Replied On October 29, 2014 11:20 AM UTC

@Karthikeyan.C After I added the Microsoft.mshtml (again) to the references I get the second exception from my previews post.



Off-Topic:

"Please refer this assembly in your project and copy the assemblies to local to get this issue fixed."
Like this ...
Did you even read my entire post:
  1. I explicitly write that I added the Microsoft.mshtml in refs.
  2. I'm not interested of Syncfusion Products. We're using them
  3. Did you event try your solution on Azure Websites? Can you provide me with example (source code + assemblies) which I can publish on our Azure subscription account



KarthikeyanC [Syncfusion]
Replied On October 31, 2014 11:36 AM UTC

Hi Milen,

Thank you for your update.

 

1)      I have attached a sample for converting HTML to PDF which we have tried in our Azure cloud.

http://files2.syncfusion.com/dtsupport/directtrac/125081/HTMLPDFAzure-1204902832.zip

 

       2)  The COM error occurs if the instances are not properly disposed, could you please make the following code changes and recycle the IIS / Application Pool and check once again?

1)      Proceed the HTMLConversion within “using” statement.

2)      Dispose the PdfDocument instance after conversion.

3)      After making these code changes, recycle the IIS / Application Pool to dispose the existing instances.

 

Here is the code snippet: 

            using (HtmlConverter html = new HtmlConverter())

            {

            // Conversion goes here

            }

            // Save PDF document

            doc.Save("Sample.pdf", Response, HttpReadType.Open);

            doc.Close(true);

 

Please try these changes and let us know if it helped.

Thanks,

Karthikeyan.C


Milen Stefanov
Replied On November 7, 2014 01:10 PM UTC

At the current stage HtmlToPdf.aspx example from WebSampleBrowser samples is not possible to run Microsoft Azure Web Sites. The reason is that there are not enough permissions to run on elevated privileges some assemblies. The core of this problem is that HtmlConverter use IE rendering engine. Feature solution promised from SyncFusion dev teams is that the WebKit rendering engine will replace the use of IE rendering engine .

Till this good times we migrate to Azure Web Roles with:
    <Runtime executionContext="elevated" />
which solve the current problem and allow using of HtmlConverter in Azure cloud environment.



Thanks to SyncFusion dev&support and specially to Karthikeyan.C for the help!
Best regards,
Milen Stefanov

KarthikeyanC [Syncfusion]
Replied On November 10, 2014 05:06 PM UTC

Hi Milen,

Thank you for your update, please let us know if you need further assistance.

 

Regards,

Karthikeyan.C


Jaycen
Replied On August 17, 2016 06:56 AM UTC

Do you have an example Web Forms project showing the HtmlConverter working in Azure? The packaged sample file generates a 502 - Web server received an invalid response while acting as a gateway or proxy server error.

Thanks!

Karthik Krishnaraj [Syncfusion]
Replied On August 18, 2016 01:19 PM UTC

Hi Milen, 
Webkit converter requires administrator privilege for HTML to PDF conversion. Azure website does not have administrative privilege so the conversion fails, as a workaround you may create a WebRole for HTML to PDF conversion part alone and host in Azure cloud, then the WebRole can be add as service reference in the main sample. You can find the sample from below link. 
WebRole for converting HTML to PDF 
WebRole for converting HTML to PDF with Azure Project 
Console Sample for using WebRole 
 
If you have faced the issue while hosting the sample in Azure cloud, then share your code snippet and more details regarding the issue. So that it will be helpful for us to investigate further.  
Please let me know if you have any other query. 
Thanks, 
Karthik. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;