CefConverter "Failed to convert webpage"

I'm trying to generate a PDF with your CefConverter HTML to PDF generator. 


My html string looks good and was working with the Webkit implementation. However, I want to run my code on a Windows Azure App Service, so I think I have to use the CefConverter. To be honest the documentation is a bit hard to follow, but that is where i landed. Anyway, the converter fails on the Convert step with almost no useful information:


            var html = await GenerateHtml(templateId, data);

            var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Cef);

            var settings = new CefConverterSettings();

            {

             TempPath = TemporaryFilesPath,

            };

            htmlConverter.ConverterSettings = settings;

            try

            {

                var document = htmlConverter.Convert(html, "https://a.website.com/");



The stack trace only shows:

   at Syncfusion.HtmlConverter.CefConverter.Convert(String url)

   at Syncfusion.HtmlConverter.CefConverter.Convert(String htmlString, String baseurl)

   at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String html, String baseurl)


With the exception message:

Failed to convert webpage


23 Replies 1 reply marked as answer

KS Karmegam Seerangan Syncfusion Team October 2, 2024 04:42 PM UTC

Hi Owen,

Thank you for reaching out to Syncfusion support.

We are unable to reproduce the reported issue on our end and it's working fine. We have attached the sample and published URL for your reference.

 

Sample:  https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTML-to-PDF-Azure-app-service2053618845

 

Published URL: Home Page - HTML_to_PDF_Azure_app_service (html-to-pdf-azure-app-service20241002215235.azurewebsites.net)

 

Please try the published URL and let us know the result. If the issue persists, we kindly request you to provide the complete code snippet, input documents, and details of the Azure hosting plan to help us replicate the issue. This information will assist us in analyzing and providing you with a prompt solution.

 

Note: The published URL is valid for 48 hours.

 

Regards,

Karmegam



OM Owen Meyer October 2, 2024 10:17 PM UTC

Thanks for your reply Karmegam.


The project sample you've supplied is missing a csproj...


Do you know if there are plans implement some more meaningful exceptions? I have seen similar errors with the other engines too. Once it was because of missing DLLs, which I solved through an internet search. It would be great if developers could get a hint as to what is wrong.


I've updated my code to try converting https://www.google.com but I get exactly the same issue.


For the record, my app is .NET 8.0 running in Visual Studio 2022 debug mode for now, with the intent of running it on an Windows Azure App Service. Non-PROD sites are currently using a Basic B1 app service plan. PROD is running Premium P2V2.


This is the method I'm calling:


        public async Task<GeneratedReport> GeneratePdfAsync(object data, string templateId, bool landscape = false)

        {

            var html = await GenerateHtml(templateId, data);


            var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Cef);

            var settings = new CefConverterSettings

            {

                ViewPortSize = new Syncfusion.Drawing.Size(1280, 0)


            };

            htmlConverter.ConverterSettings = settings;

            try

            {

                var document = htmlConverter.Convert("https://www.google.com");

                var stream = new MemoryStream();


                document.Save(stream);

                document.Close(true);


                stream.Position = 0;


                return new GeneratedReport

                {

                    Content = stream,

                    ContentType = "application/pdf"

                };

            }

            catch (Exception ex)

            {

                // Log or handle the exception

                _logger.LogError(ex, $"Conversion failed: {ex.Message}");

                throw;

            }

        }

And this is my CSPROJ:


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>

    <TargetFramework>net8.0</TargetFramework>

    <ImplicitUsings>enable</ImplicitUsings>

    <Nullable>disable</Nullable>

    <FileAlignment>512</FileAlignment>

    <Deterministic>true</Deterministic>

    <AppConfig>App.config</AppConfig>

    <AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>

    <Configurations>Debug;Release</Configurations>

  </PropertyGroup>

  <ItemGroup>

    <PackageReference Include="CsvHelper" Version="33.0.1" />

    <PackageReference Include="Razor.Templating.Core" Version="2.0.0" />

    <PackageReference Include="Syncfusion.HtmlToPdfConverter.Cef.Net.Windows" Version="27.1.51" />

    <PackageReference Include="System.Interactive.Async" Version="6.0.1" />

    <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.8" />

  </ItemGroup>

  <ItemGroup>

    <None Update="runtimes\win-x64\native\libeay32.dll">

      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

    </None>

    <None Update="runtimes\win-x64\native\libssl32.dll">

      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

    </None>

    <None Update="runtimes\win-x64\native\ssleay32.dll">

      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

    </None>

  </ItemGroup>

</Project>

Do I need to use the CEF engine for Windows Azure App Service Plans? Or can I use Webkit?



OM Owen Meyer October 3, 2024 04:03 AM UTC

Hi again,

I have got this working locally again using - Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core --version 27.1.51


However, it still won't work in my Azure (Windows Basic B1) environment.


This is the method:

 public async Task<GeneratedReport> GeneratePdfAsync(object data, string templateId, bool landscape = false)

 {

     var html = await GenerateHtml(templateId, data);


     var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);

     var settings = new WebKitConverterSettings

     {

         Margin = new Syncfusion.Pdf.Graphics.PdfMargins

         {

             All = 20

         },

         Orientation = landscape ? Syncfusion.Pdf.PdfPageOrientation.Landscape : Syncfusion.Pdf.PdfPageOrientation.Portrait,

         TempPath = TemporaryFilesPath,

         DisableWebKitWarning = true

     };

     htmlConverter.ConverterSettings = settings;

     try

     {

         var document = htmlConverter.Convert(html, "https://wrms.website.com/");


         var stream = new MemoryStream();


         document.Save(stream);

         document.Close(true);


         stream.Position = 0;


         return new GeneratedReport

         {

             Content = stream,

             ContentType = "application/pdf"

         };

     }

     catch (Exception ex)

     {

         // Log or handle the exception

         _logger.LogError(ex, $"Conversion failed: {ex.Message}");

         throw;

     }

 }


This is the error caught in App Insights - apologies for the image quality, the limit is 100kb


Screenshot 2024-10-03 165726.png



AM Arumugam Muppidathi Syncfusion Team October 3, 2024 10:41 AM UTC

Hi Owen,

Please find the details below

Do I need to use the CEF engine for Windows Azure App Service Plans? Or can I use Webkit?

 

The WebKit rendering engine internally uses the QtWebKit browser to perform HTML to PDF conversion. It is a legacy rendering engine, that has some known rendering issues and limitations, some of the advanced Bootstrap CSS styles are not supported. So we strongly recommended to use our cef rendering engine to perform HTML to PDF conversion in Azure app service windows.  You can find our UG documentation below to perform HTML to PDF conversion using CEF rendering engine in Azure app service windows

 

UG: Convert-html-to-pdf-in-azure-app-service-windows

 

However, we have attached the sample using CEF rendering engine and published URL for your reference

Sample: HTML-to-PDF-AzureAppServiceWindows-CEF-2069967933
Published URL: https://html-to-pdf-azureappservicewindows-cef20241003134157.azurewebsites.net/

Please try the above sample and let us know the result.

I have got this working locally again using - Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core --version 27.1.51

 

However, it still won't work in my Azure (Windows Basic B1) environment.

 

We have checked the provided issue screenshot on our end.  We suspect that the exception may occur due to the missing of VC++ 2010 redistributable (MSVCP100.dll and MSVCR100.dll) in your Azure App service environment. WebKit rendering requires VC++ 2010 redistributable to perform the conversion. So, please include the below VC++ redistributable files in the QtBinaries folder and select copy if newer option in the properties then publish it in azure app service to resolve the issue.

 

We have attached screenshot and VC++ DLLs for your reference.

 

VC ++ DLLs: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Redistributable147672089
 

 

Screenshot:



As we mentioned earlier, Webkit rendering engine is a legacy rendering engine.  If you still want to use webkit rendering engine, please try the above solution and let us know the result.
 


Regards,
Arumugam M



BR Bruce Richards October 5, 2024 11:00 AM UTC

Hi, 


I too am having this problem and downloading your Sample it also fails with the  "Failed to convert webpage" - 

This exception was originally thrown at this call stack: [External Code].  The provided URL doesn't work?


Regards


p.s. apologies to Owen Meyer for hijacking his thread.



AM Arumugam Muppidathi Syncfusion Team October 7, 2024 04:13 PM UTC

Hi Bruce,


We have checked your issue on our end.  Upon further analysis, the reported issue was not reproduced and the conversion is working fine when deploying the application in Azure app service Windows.  However, we have attached the demo video for sample running below for your reference.

 

Demo: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Demo_video1069071005

Please see the attached video and let us know the result.  If you are still facing issue, we kindly request you to share the modified sample, dotnet version, currently used package name and version, azure hosting plan with us to replicate the issue on our end and provide a prompt solution.


Regards,
Arumugam M



OM Owen Meyer October 7, 2024 10:14 PM UTC

I'm still attempting to use the WebKit converter - it works locally, but not in Azure. I added the VC++ binaries to the project, but it is still failing with the same message:



The binaries are added like so:

Image_7122_1728339143403


And they are present, as you can see:

Image_5853_1728339150832


Am I missing something?



AM Arumugam Muppidathi Syncfusion Team October 8, 2024 02:52 PM UTC

Hi Owen,


We have checked your issue on our end.  As we said earlier, the reported issue was not reproduced on our end and the conversion is working fine when hosting the application in Azure app service windows.  However, we have attached the demo video for sample running below for your reference

Demo: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Demo_video-1224792960

Please find the sample to perform HTML to PDF conversion using Webkit rendering engine and published URL below

Sample: HTML-to-PDF-Webkit-AzureAppService-Windows253590483

Published URL: https://html-to-pdf-webkit-azureappservice-windows20241008124719.azurewebsites.net/

 

Note: The published URL will be expired after 48 hours.

 

Please try the above sample and let us know the result.  If you are still facing issue, we kindly request you to share the modified sample, issue replicated code snippet with us. This information will be more helpful for us to analyze and provide you with a prompt solution.


Regards,
Arumugam M



BR Bruce Richards replied to Arumugam Muppidathi October 8, 2024 05:15 PM UTC

Hi Arumugam,

I think I have a different issue to Owen and as this is his thread I shall not interject further as I don't believe resolution of my issue will necessarily sort his.

Can you advise if I can start a different support threa




AM Arumugam Muppidathi Syncfusion Team October 9, 2024 05:36 AM UTC

Hi Bruce,


Yes, you can create a new forum for any new issue to ensure better follow-up with all the details of your complete issue.


Regards,
Arumugam M



OM Owen Meyer October 13, 2024 08:56 PM UTC

Hi - this is still a problem for me.


I just attempted to use the Cef library again, but it won't run locally, with this exception:

Image_3396_1728852994052


Its still a .NET 8.0 project referencing the latest published version:


    <PackageReference Include="Syncfusion.HtmlToPdfConverter.Cef.Net.Windows" Version="27.1.52" />


This is the method that is failing - remember this works with WebKit, until I upload it to Azure:



        public async Task<GeneratedReport> GeneratePdfAsync(object data, string templateId, bool landscape = false)

        {

            var html = await GenerateHtml(templateId, data);


            var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Cef);

            var settings = new CefConverterSettings

            {

                Margin = new Syncfusion.Pdf.Graphics.PdfMargins

                {

                    All = 20

                },

                Orientation = landscape ? Syncfusion.Pdf.PdfPageOrientation.Landscape : Syncfusion.Pdf.PdfPageOrientation.Portrait,

                TempPath = TemporaryFilesPath,

                MediaType = MediaType.Print,

                HtmlEncoding = Encoding.UTF8

            };

            htmlConverter.ConverterSettings = settings;

            try

            {

                var document = htmlConverter.Convert(html, "https://wrms.watco.com/");


                var stream = new MemoryStream();


                document.Save(stream);

                document.Close(true);


                stream.Position = 0;


                return new GeneratedReport

                {

                    Content = stream,

                    ContentType = "application/pdf"

                };

            }

            catch (Exception ex)

            {

                // Log or handle the exception

                _logger.LogError(ex, $"Conversion failed: {ex.Message}");

                throw;

            }

        }



OM Owen Meyer October 13, 2024 09:14 PM UTC

Are there prerequisites for the Cef converter?

I've attached an example of the HTML I'm failing to convert.


Attachment: Untitled1_7bf31b01.zip


OM Owen Meyer October 13, 2024 09:24 PM UTC

I've just tried dropping your code in:


var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Cef);

var cefConverterSettings = new CefConverterSettings();

//Set Blink viewport size.

cefConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0);

//Assign Blink converter settings to HTML converter.

htmlConverter.ConverterSettings = cefConverterSettings;

try

{

    var document = htmlConverter.Convert("https://www.google.com");


    var stream = new MemoryStream();


    document.Save(stream);

    document.Close(true);


    stream.Position = 0;


    return new GeneratedReport

    {

        Content = stream,

        ContentType = "application/pdf"

    };

}

catch (Exception ex)

{

    // Log or handle the exception

    _logger.LogError(ex, $"Conversion failed: {ex.Message}");

    throw;

}

I can't convert google.com either:

Image_5966_1728854667777




OM Owen Meyer October 14, 2024 12:35 AM UTC

I'm trying WebKit again... It still works locally and fails on Azure with the attached error captured in App Insights.



Image_4323_1728866094394



Attachment: query_data_aba4d9e0.zip



OM Owen Meyer October 14, 2024 03:35 AM UTC

OK - I have solved the WebKit in Azure issue.


The Azure application must not be deployed with WEBSITE_RUN_FROM_PACKAGE = 1. Once I removed the setting it started working.


It would be great if the API provided more meaningful exceptions. This has taken more than a day of making changes, redeploying, and testing. 

I'm going to have a little play to see if I can get the CEF engine working, but again the exception messages aren't very helpful. Do you have a list of prerequisites?


Marked as answer

AM Arumugam Muppidathi Syncfusion Team October 14, 2024 12:55 PM UTC

Hi Owen,


Thank you for the update regarding Webkit rendering engine.

We have checked your issue on our end regarding Cef rendering engine.  Upon further analysis, we suspect that the reported issue may occur due to improper structure of runtime folders or runtime dlls are not copied properly in your project's location.  We kindly request you to ensure your project structure should be similar to the below structure and the below specified dlls should be present in the specified structure.

1) bin->Debug->net8.0->runtimes->win-x64->lib->netcoreapp3.1 

 The below highlighted dlls should be present inside netcoreapp3.1 folder

undefined



2) bin->Debug->net8.0->runtimes->win-x64->native

Kindly make sure below highlighted 21 files should be present inside native folder.

undefined



3) Make sure CefSharp.BrowserSubprocess.runtimeconfig.JSON file in runtimes folder(bin\Debug\net8.0\runtimes\win-x64\native) is similar to the below JSON file.  This JSON file are copied during runtime for .net 8.0 project, So, the runtimesOption should be net8.0 in JSON file.  This ensures the runtimes JSON file are copied for .net8.0 project.

undefined



We kindly request you to check the runtime dlls are properly copied into your project's location as mentioned above. This ensures that the HTML to PDF conversion using CEF rendering engine is working properly.

Please ensure the above and let us know the result.  Kindly get back to us if you need any further assistance in this.


Regards,
Arumugam M



OM Owen Meyer October 16, 2024 01:00 AM UTC

My solution is structured such that i have a Reports project which is referenced by the main web application. The reports project has a direct reference to the SyncFusion library:

<PackageReference Include="Syncfusion.HtmlToPdfConverter.Cef.Net.Windows" Version="27.1.53" />


After Rebuilding the Reports project I see this:
Image_6756_1729038967175

Here the runtimeconfig.json has tfm set to "net8.0". The runtimes folder is otherwise empty.


In the referencing project I see the following:
Image_8481_1729039047411


I.e. there are quite a few libraries missing from the native folder. Also, the tfm setting in the runtimeconfig is "netcoreapp3.1"

How should I include the missing files?



OM Owen Meyer October 16, 2024 01:16 AM UTC

Another thing, I just tried your sample from October 3, 2024 10:41 AM UTC

https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTML-to-PDF-AzureAppServiceWindows-CEF-2069967933

Untitled.png

When I tried it, I got this exception:

PdfException: Failed to convert webpage

  • Syncfusion.HtmlConverter.CefConverter.Convert(string url)

  • Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(string url)

  • HTML_to_PDF_AzureAppServiceWindows_CEF.Controllers.HomeController.ConvertToPdf() in HomeController.cs

    1. PdfDocument document = htmlConverter.Convert("https://www.google.com");
  • lambda_method18(Closure , object , object[] )



AM Arumugam Muppidathi Syncfusion Team October 16, 2024 11:51 AM UTC

Hi Owen,

We have checked the provided screenshot on our end.  Upon further analysis, we found that the chromium dlls are not copied at runtimes folders during conversion process.  The CEF HTML to PDF conversion fully depends on runtime assemblies to perform HTML to PDF conversion. In some projects NuGet packages might not directly copy their assemblies and runtime files to the output directory. We can overcome the reported issue by following the below steps

Add <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> tag in the csproj file to copy the required runtime assemblies in the bin folder as highlighted in the below screenshot.

undefined



However, if you are still facing any issue we kindly request you to install the below package with version 119.4.3 through Manage NuGet packages along with our Syncfusion.HtmlToPdfConverter.Cef.Net.Windows package.  This ensures the chromium runtime files are copied in the runtimes folder.

NuGet\Install-Package chromiumembeddedframework.runtime.win-x64 -Version 119.4.3

undefined


Please try the above solution and get back to us.  We look forward to hear from you on whether this solution resolves the reported issue.


Regards,
Arumugam M



OM Owen Meyer October 16, 2024 08:24 PM UTC

Adding CopyLocalLockFileAssembies did not work. This is the bin folder content in the parent project:

Image_5997_1729110245569



OM Owen Meyer October 16, 2024 08:46 PM UTC

Once I add the explicit reference to chromiumembeddedframework.runtime.win-x64 my application has a fatal error:


[1017/094240.811:FATAL:gpu_data_manager_impl_private.cc(448)] GPU process isn't usable. Goodbye.


The native folder has many more files now, but the runtimeconfig.json still has tfm equal to netcoreapp3.1


Image_6699_1729111550003



OM Owen Meyer October 16, 2024 10:04 PM UTC

Hi - I have this working locally now. I added a reference to the parent project:


        <PackageReference Include="CefSharp.OffScreen.NETCore" Version="119.4.30" />


I removed the other suggestions you made and it still works. 


However, it does not work in Azure.

Image_4593_1729116246443





AM Arumugam Muppidathi Syncfusion Team October 17, 2024 12:22 PM UTC

Hi Owen,


Upon further investigation, we suspect that the reported issue may be specific to your project.  As we mentioned earlier, your project doesn't have proper structure and the necessary runtime DLLs are not being copied properly.  This is because the packages are not referenced properly.  We kindly request you to share your complete project with us.  This will be more helpful for us to analyze and provide you with a prompt solution.

However, we have created sample application to perform HTML to PDF conversion in Azure app service(Windows).  The conversion is working fine on our end. When the application is published to Azure, a new folder named "Release" is created inside the obj folder. This "Release" folder contains the DLLs required to run the application on Azure App Service. We have attached this Release folder for your reference.


Release folder: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Release-459964004


Please ensure that your project's release folder structure matches the attached folder structure, as this is necessary for the application to function properly on Azure.


Kindly get back to us with your project for any further assistance in this.  We look forward to hear from you on whether this solution resolves the reported issue.


Regards,
Arumugam M


Loader.
Up arrow icon