PDF Viewer's service is throwing an exception "The type initializer for 'Syncfusion.EJ2.PdfViewer.Pdf

Hello,

I have a question regarding the PDF Viewer's service implemented in ASP.NET Core in Linux environment. The service is working properly when I run it locally, however unfortunately it is not working in production mode. I keep getting the following error:

"The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception." 

but it didn't help me at all. The libpdfium.so file is present and located in project's main directory.

Best Regards,
Ignacy Mielniczek

18 Replies 1 reply marked as answer

DM Dhivyabharathi Mohan Syncfusion Team June 10, 2021 01:13 PM UTC

Hi Ignacy,   
    
  Thank you for contacting Syncfusion support.   
    
We suspect that the write access permission is denied, so the exception is thrown. We have embedded the Pdfium rendering engine in our PDF Viewer for robust rendering. So, the Pdfium.dll will be generated on runtime within your project location. Based on the provided details, we suspect that you are using libpdfium.so which will be generated for the Linux platform. So, we need to use Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux NuGet package in your environment. Could you kindly share more details on whether you are using Linux Docker to host the project? It will be helpful for us to investigate further and provide the details at the earliest.   
 
Regards, 
Dhivya. 



IM Ignacy Mielniczek July 13, 2021 03:13 PM UTC

Hello Dhivya,

I am sorry for taking so long to reply. 

I am creating a Linux container using Docker Desktop with WSL 2 engine (Ubuntu distro) on Windows 10. Also, I have already installed Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux NuGet package for my project and I have checked if this issue is related with write access permission like you mentioned above. However, it isn't. Besides that, I have added the following line of code which should generate us the libpdfium.so​ every time when PdfViewer Controller receives the request to Load the pdf file:

PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";

Unfortunately, I have noticed that libpdfium.so file is being created in a directory named '\'​, not in our project's root path. Do you think this might be the main reason that I still get the error  "The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception."

Best Regards,

Ignacy Mielniczek



DM Dhivyabharathi Mohan Syncfusion Team July 14, 2021 07:48 AM UTC

Hi Ignacy, 
 
In our PDF Viewer, we have embedded the Pdfium rendering engine in our PDF Viewer for robust rendering. So, Pdfium dll will be generated on runtime within your project location. We suspect that the issue is due to the missing of the libpdfium.so assembly in the published Docker environment. So, we suggest you place the assembly in the project location and enabling the copy to Output Directory property to copy always and to publish the same. To work with PDFIUM in the LINUX environment we need to add the following commands in the docker file to install the dependencies.   
  
Commands:  
  
RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so   
# install System.Drawing native dependencies   
RUN apt-get update && apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libx11-dev   
RUN ln -s libgdiplus.so gdiplus.dll   
  
  
  
  
 
Could you kindly try this and let us know whether the issue resolves or not? If the issue is not resolved, kindly share the docker file or modified sample in which you are facing this issue. It will be helpful for us to investigate further and provide the details at the earliest. 
 
 
Regards, 
Dhivya. 


Marked as answer

IM Ignacy Mielniczek July 14, 2021 04:00 PM UTC

Hi Dhivya,

Thank you very much for a quick response. I am writing to you to inform you that the issue has been resolved by adding the commands which you have sent me above, to our project's DockerFile.

One more time thanks for the help. :)

Best Regards,

Ignacy Mielniczek



DM Dhivyabharathi Mohan Syncfusion Team July 15, 2021 06:39 AM UTC

Hi Ignacy, 


Thank you for your update. We are glad to know that the reported issue is resolved. 


Regards, 
Dhivya. 



ET Evrard tSerstevens January 13, 2022 04:24 PM UTC

Hi, 


We are facing the same issue, been working on it for 4 days and we keep on getting the error "JsonResult: The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception.". 

We are not able to access the gitlab link mentioned above btw. 

Could you please help please?


Thanks, 


Evrard



SK Shamini Kiruba Sobers Syncfusion Team January 14, 2022 10:06 AM UTC

Hi Evrard, 
 
 
We suspect that issue is due to the write access permission denied in the environment. We will create the pdfium.dll based on the operating system at the runtime. So, could you please try copying the below provided x64 and x86 folder and paste inside the folder into your project to resolve the issue or enable the write permission for that folder?
  
 
    
Note:    
· Kindly use both the client and server-side of the same version in your project    
· Ensure whether the Pdfium dll will be created in your project during runtime. Else we can also place the pdfium assemblies in any of the production environment locations and refer to the path by using the ReferencePath API.    
    
For example:     
   
If the Pdfium assembly is available in this path C:\Pdfium\x64 or D:\Pdfium\x86, the reference path should be PdfRenderer.ReferencePath = "C:/";     
    
The parent folder has to be provided as the path in the ReferencePath API.     
Note: Provide this path in the Load method of the PDFViewerController.cs     
PdfRenderer PdfRenderer = new PdfRenderer();     
PdfRenderer.ReferencePath = @"C:/";     
  
 
  
 
 
Kindly try this and let us know if the issue resolves or not. If not, please share the response details in the network tab and PDF document in which you are facing the issue. This will be helpful to investigate further and provide the solution at the earliest.
 
  
Regards, 
Shamini 



SK Sravan Kumar Moravaneni May 11, 2022 07:38 AM UTC

Hi Guys, I'm using angular ejs-pdfviewer and recently I have updated the package to "20.1.52" and also in the .Net Core updated all the Nuget to this version and also registered the new license key for this version. And, in my local system pdfviewer have worked fine only. But, after the deployment and in the deployed site, I'm getting this error, please check the screenshot for reference here https://prnt.sc/tEh5yas35hGe ., Is there anything to do related to the "PdfiumNative" after updating to the latest nuget packages of the syncfusion? And also FYI, Please check the screenshots related to pdfium in my project below.,

 1. https://prnt.sc/n6Tg6YimAA-j  --> This is related to the "pdfium" folder referencing in the project (Worked previously, but now                                                                      getting error in the deployed site.)
 2. https://prnt.sc/KZhUlasJ3MGl --> This is related to the syncfusion Nuget package related to the .net core pdfviewer windows


And lastly, for our project, few sites were deployed under the windows environment (they were working fine only)  and few sites will get deployed under the Linux environment (in these, it is throwing error). Can you please tell me what to do for this.

 Please, provide me a solution for this as this is an important feature in our project.



VS Vasugi Sivajothi Syncfusion Team May 12, 2022 09:00 AM UTC

Hi Sravan,


We suspect that the reported issue in the Linux platform is due to libpdfium.so is not referred on your end. We will create the pdfium based on the operating system at the runtime. So pdfium.dll (libpdfium.so) will be generated on runtime within the project location. We have maintained the separate NuGet packages based on the OS. So, if you deploy the PDF Viewer project on Linux then you must refer to the corresponding NuGet (Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux) to run the PDF Viewer.


Pdfium dll: pdfium.dll


For more information, please refer to the below link.

https://ej2.syncfusion.com/aspnetcore/documentation/pdfviewer/how-to/resolve-pdfium-issue


Kindly try this and let us know if you have any concerns about this.


Regards,

Vasugi.



SA shoaib Ahmed May 18, 2022 06:13 AM UTC

App version: .Netcore 3.1

I have created a lambda function and trying to convert PDF file to images. Its working fine on my local machine but when i deploy my lambda function to aws it gives error  "The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception."

I have set reference path but still not working.

https://ej2.syncfusion.com/aspnetcore/documentation/pdfviewer/how-to/resolve-pdfium-issue

Above URL help is not working.








SK Shamini Kiruba Sobers Syncfusion Team May 19, 2022 06:03 PM UTC

Hi Shoaib,


We are analyzing your query and we will provide further details on May 20, 2022.


Regards,

Shamini



VS Vasugi Sivajothi Syncfusion Team May 23, 2022 09:40 AM UTC

Hi shoaib,


Currently, PDF Viewer is not working in the AWS lambda. We have raised the query in the AWS forum regarding installing the dependencies in the AWS environment. We will let you know once we get the update from the forum. You can track the status using the below feedback link,


https://www.syncfusion.com/feedback/31825/pdf-viewer-not-working-in-aws-environment 


Regards, 

Vasugi





CL Clay February 23, 2023 07:33 PM UTC

Hello,


I am facing a similar issue as everything listed above and have tried the following solutions:

- Checking write permissions on Pdfium folder in project

- Setting reference path to Pdfium folder

- Installing listed packages from the Docker solution (my project does not use Docker but I manually installed what was listed)


I am developing on Windows and using the Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows works great with the inclusion of 'Pdfium/x64/pdfium.dll' during local development. However, I am deploying to a Linux environment on AWS Beanstalk and is it there that the pdfium exception occurs. I have temporarily switched to developing on Ubuntu 22.04 to try and debug this issue locally with more control. I have added 'libpdfium.so' to the Pdfium folder and switched to Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux and am unable to get rid of the error.


My target framework is .net 6 and I am using package version 20.4.0.38 for all installed Syncfusion packages. I was previously using .net 7 while developing on windows but switched to .net 6 as an attempt to solve the issue.


Any help on the issue is greatly appreciated.

Thank you,

Andrew



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team February 24, 2023 01:08 PM UTC

Use the below commands to install the pdfium dependency in Linux machine.  

  

  sudo cp -u /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so

    sudo apt-get update

    sudo apt install libgdiplus

 

 

If you are still facing the issue after package installation, Please share the below details.

  • Check the machine configuration using uname –m command and share the machine configuration details to us.

 

The above step were not resolved the error. Please share the network tab response details to check further.



CL Clay replied to Chinnamunia Karthik Chinna Thambi February 24, 2023 07:55 PM UTC

Hi Chinnamunia,


I did what you suggested on Ubuntu and it worked great! 


I am unfortunately unable to replicate this on Amazon linux which is where I am deploying to. I am assuming this has to do with installing the correct native dependencies, and I am wondering how I might satisfy these requirements on Amazon linux. I am running 64bit Amazon Linux 2 v2.5.0. So far I was able to successfully install libgdiplus and made a copy of /lib64/libdl.so.2 as /lib64/libdl.so but have been unable to replicate anything else that was successful for me on Ubuntu.


Thank you.



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team March 2, 2023 04:41 PM UTC

I did what you suggested on Ubuntu and it worked great! 

 

We are glad to know the issue is resolved on your end.

I am unfortunately unable to replicate this on Amazon linux which is where I am deploying to. I am assuming this has to do with installing the correct native dependencies, and I am wondering how I might satisfy these requirements on Amazon linux. I am running 64bit Amazon Linux 2 v2.5.0. So far I was able to successfully install libgdiplus and made a copy of /lib64/libdl.so.2 as /lib64/libdl.so but have been unable to replicate anything else that was successful for me on Ubuntu.

 

We suspect your query is to add the dependencies in the Amazon Linux environment. If yes, Please add the below Linux dependencies installation command in Amazon Linux environment to install the libgdiplus package.

 

sudo ln -s /usr/lib64/libdl.so.2 /usr/lib64/libdl.so

sudo yum install -y amazon-linux-extras

sudo amazon-linux-extras install epel -y

sudo yum install -y libgdiplus

 

Please refer the below link also for how to install a software package in Amazon Linux

 

https://bobcares.com/blog/install-a-software-package-from-the-extras-library-on-ec2/

 

If you are still facing any issues, Share the network tab and console tab screenshot for the issue and also share the AWS instance details like AWS EKS or Lambda function.

 



RR Rahul Ravi January 21, 2025 12:27 PM UTC

Hi,

We recently migrated our project to Angular 17 and during this process, we also upgraded the Syncfusion package. We are using the PDF viewer in one of the modules, and our implementation involves both server-side and client-side rendering.

After analysis, we discovered that the PDF viewer version @syncfusion/ej2-angular-pdfviewer (26.2.10) doesn't support both rendering modes. We rolled back to version 25.2.3, and both rendering modes worked as expected.

However, since our application migration was recent, we cannot revert just the PDF viewer to version 25.2.3. We would like to know if this is a bug or if there’s something we need to do on our end to make version 26.2.10 support both rendering modes.

Any assistance would be greatly appreciated.


I have attached the screenshot of the error we are facing for your reference:



Thanks,

Rahul



PA Priyadharshini Annamalai Syncfusion Team January 22, 2025 11:24 AM UTC

Hi Rahul,

We recommend verifying the issue using the latest version of the PDF Viewer package (28.1.41), as this version may have resolved the rendering mode compatibility issue. We have provided a sample for testing below with the mentioned version (26.2.10)

If the issue persists, could you please provide the following details to help us investigate further and offer an accurate solution?

  1. A video demonstrating the issue.
  2. A modified sample reproducing the issue.
  3. The specific PDF documents causing the problem.

If upgrading to the latest version is not feasible or you face any challenges, please let us know, and we will assist you further.

Sample: Nwdaqob9 (forked) - StackBlitz


Regards,

Priyadharshini



Loader.
Up arrow icon