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
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.
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
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?
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
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 |
|
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
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.
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
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:
And they are present, as you can see:
Am I missing something?
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
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
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
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:
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;
}
}
Are there prerequisites for the Cef converter?
I've attached an example of the HTML I'm failing to convert.
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:
I'm trying WebKit again... It still works locally and fails on Azure with the attached error captured in App Insights.
Attachment: query_data_aba4d9e0.zip
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?
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
2) bin->Debug->net8.0->runtimes->win-x64->native
Kindly make sure below highlighted 21 files should be present inside native folder.
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.
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
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:
After Rebuilding the Reports project I see this:
Here the runtimeconfig.json has tfm set to "net8.0". The runtimes folder is otherwise empty.
In the referencing project I see the following:
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?
Another thing, I just tried your sample from October 3, 2024 10:41 AM UTC
When I tried it, I got this exception:
HomeController.csHi 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.
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 |
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
Adding CopyLocalLockFileAssembies did not work. This is the bin folder content in the parent project:
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
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.
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