I'm trying to convert office documents to pdf so they can be displayed in my Blazor app.
I've followed the following documentation https://blazor.syncfusion.com/documentation/pdfviewer/how-to/load-office-files but whenever I try I get the following error:
Unhandled exception rendering component: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
---> System.DllNotFoundException: libSkiaSharp
--- End of inner exception stack trace ---
at Syncfusion.Drawing.SkiaSharpHelper.Image..ctor(Int32 width, Int32 height)
at Syncfusion.Drawing.SkiaSharpHelper.Bitmap..ctor(Int32 width, Int32 height)
at Syncfusion.DocIORenderer.RenderHelper.GetBitmap(Int32 width, Int32 height)
at Syncfusion.DocIO.Rendering.DrawingContext.CreateBitmap(Int32 width, Int32 height)
at Syncfusion.DocIORenderer.DocIORenderer.ConvertToPDF(WordDocument wordDocument)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
I've got the following packages installed:
<PackageReference Include="Syncfusion.Blazor.Themes" Version="188.8.131.52" />
<PackageReference Include="Syncfusion.Blazor.WordProcessor" Version="184.108.40.206" />
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="220.127.116.11" />
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="18.104.22.168" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="22.214.171.124" />
While converting Office files to PDF in Blazor WASM application, the reported problem occurs due to SkiaSharp dependency.
To resolve the reported problem, kindly do the following steps in your Blazor WASM application,
Please refer our KB documentation to know about how to convert Word to PDF in Blazor WASM app,
Note: We will plan to update these details in this documentation also.
Thanks - that worked perfectly when running locally, but the same issues come back as soon as it's deployed to Azure.
Felix, we tried to reproduce the reported issue by
publishing the Blazor WASM application in Azure App Service PremiumV3 (P2v3).
But it worked properly without any issue in our end.
Can you please share the details of the platform in Azure(Example: Azure App Service Linux, Azure Kubernetes Service…) that you tried to publish the sample. This will be helpful for us to replicate the reported issue in the respective platform. And so that we can share the solution as soon as possible.
When I'm programming the application it's on MacOS dotnet 7 and it's being deployed via GitHub Actions to an Azure App Service - Windows (using dotnet 7)
Felix, on our side,
we are currently checking with our organization to set up a similar environment
(deploy via GitHub Actions to an Azure App Service - Windows (using dotnet 7))
to replicate the exact problem and will update further details on 27th
Meantime, we have attached the Blazor WASM sample in net7.0 target. We suggest you to deploy the attached sample at your end and provide us confirmation whether you are facing issue in this sample.
If the issue is not reproduced using the attached sample application at your end, then could you please modify the attached sample as an issue reproducible sample application and share us.
Which will be helpful to reproduce the exact issue at our end and will provide you appropriate solution at the earliest.
The project you sent is not the same as the one I am using. It's a WebAssembly ASP.NET Core Hosted application so it also has a server and shared project.
Everything else is the same as your code.
Felix, still we are checking with our organization to set up a the environment. Sorry for the delay. We will update you with more details on 28th February 2023.
Felix, we set up the environment
and reproduced the reported error in Blazor WASM app while deployed via GitHub
Actions to an Azure App Service - Windows (using dotnet 7) in our end. We will check
and update you with further details on two days.
Felix, on further analysis,
we have found that the reported exception is due to the SkiaSharp package and not
related to Syncfusion Word (DocIO) library.
Internally, we are using the SkiaSharp package as a dependency package of DocIORenderer to convert Word document to PDF. The reported libSkiaSharp exception reproduced in both .NET 6 and .NET 7 when deploy the Blazor client app to Azure App Service (Windows) using GitHub Actions.
We have found the solution to resolve the reported libSkiaSharp issue in .NET 6 target when deploy the Blazor client app to Azure App Service (Windows) using GitHub Actions.
Please do the below steps to resolve the libSkiaSharp issue in .NET 6,
1. Add the WasmBuildNative property group in Blazor client csproj file.
2. Add the “dotnet workload restore” command before the build command in the GitHub workflow (YAML) file.
Please find the .NET 6 Blazor client sample application and its GitHub workflow (YAML) file from the below attachment.
We are facing some other problems due to SkiaSharp in .NET 7 which are specific to SkiaSharp package and not related to our Word library. Currently, we are investigating further to resolve the reported libSkiaSharp issue in .NET 7
Until, we suggest you to use .NET 6 along with above suggestion.
Thanks for this; however, we cannot, and are not willing to, roll back to using .NET 6, so please keep me informed on when it will work on .NET 7.
Felix, as we
mentioned earlier, the reported problem is due to the SkiaSharp library which
in one of the dependent on DocIORenderer
library. We have reported this issue to SkiaSharp team. Once the reported issue resolved by the SkiaSharp
team, we will update you the details.
Please find the bug report created for SkiaSharp team,
We will follow the above link to know the status of the issue and keep trying out the solutions provided by SkiaSharp team.
Any update on this? If there isn't an update, I think you need to start looking at using a different package...
Felix, we are using SkiaSharp
library for long years and also in multiple environments ( as an
alternative for System.Drawing GDI functionalities). During Word to PDF
conversion, we are measuring each contents (text, images, shapes) to layout the
contents and preserve in the position as like Microsoft Word application.
Because, the position and layouting information are not available from Word
document file structure. We are facing this problem with specific to particular
environment alone. Using the different package instead of SkiaSharp is not
feasible at our since it rises more breaks in our existing customers and also
it leads to more work to change the entire Word to PDF architecture to preserve
contents as equivalent to Microsoft Word.
We will follow up with the below thread and will update you once we got any solution.