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

Hi
I'm working on a Asp.Net Core 3.1 API and with Syncfusion package version 17.4.0.49 and try to render a PDF. The solution works on localhost but not on the production server. The pdfviewer.Load() function returns a string: "The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception.".

What could the problem be? How can I get a more detailed error message?

Regards,
Christof


        [HttpPost]
        [Route("load")]
        public async Task<ActionResult> Load([FromBody] Dictionary<string, string> jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer(_cache);

                object jsonResult = new object();

                HttpClient httpClient = new HttpClient();
                var pdf = await httpClient.GetAsync(jsonObject["document"]);
                var stream = await pdf.Content.ReadAsStreamAsync();
                jsonResult = pdfviewer.Load(stream, jsonObject);
                _logger.LogError("pdfviewer loaded {jsonResult}", jsonResult);
                return Ok(JsonConvert.SerializeObject(jsonResult));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "PDF Dokument anzeigen fehlgeschlagen.", null);
                return this.StatusCode(StatusCodes.Status500InternalServerError, "Das PDF kann nicht angezeigt werden.");
            }
        }

37 Replies

AA Akshaya Arivoli Syncfusion Team February 18, 2020 01:55 PM UTC

Hi Christof, 

Thank you for contacting Syncfusion support. 

Based on the provided details 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 Pdfium dll will be generated on runtime within your project location.    
    
However, we have exposed the ReferencePath API to set the pdfium library location path. We can place the pdfium library in project location and refer the project location to the ReferencePath. Please find the below code to set the pdfium location inside the wwwroot folder.   
  
Code snippet:     
 
PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";   
    
Example:    
     
public IActionResult Load([FromBody] Dictionary<stringstring> jsonObject)   
        {   
           PdfRenderer pdfviewer = new PdfRenderer(_cache);   
          PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";   
            MemoryStream stream = new MemoryStream();   
            object jsonResult = new object();   
            if (jsonObject != null && jsonObject.ContainsKey("document"))   
            {   
                if (bool.Parse(jsonObject["isFileName"]))   
                {   
                    string documentPath = GetDocumentPath(jsonObject["document"]);   
                    if (!string.IsNullOrEmpty(documentPath))   
                    {   
                        byte[] bytes = System.IO.File.ReadAllBytes(documentPath);                           
                        stream = new MemoryStream(bytes);   
                    }   
                    else   
                    {   
                        return this.Content(jsonObject["document"] + " is not found");   
                    }   
                }   
                else   
                {   
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]);   
                    stream = new MemoryStream(bytes);   
                }   
            }   
            jsonResult = pdfviewer.Load(stream, jsonObject);   
            return Content(JsonConvert.SerializeObject(jsonResult));   
        }   
     
We have also shared the Pdfium dll in the below link,   
  
 
Note: 
 
Kindly use the  Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux package in your application for linux environment . Also, ensure whether the library dependencies of libpdfium.so are installed properly. If not, please execute the following command to install the dependencies   

RUN apt-get update \     
    && apt-get install -y --allow-unauthenticated \     
        libc6-dev \     
        libgdiplus \     
        libx11-dev \     
        curl \     
        vim \     
        supervisor \     
        procps     
 

 
Please try this and revert us with more details if you are still facing the issue and confirm us whether you are hosting the application in Windows or Linux environment. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 



CM Christof Müller February 24, 2020 09:54 AM UTC

Hi Akshaya
Great, that's the solution! Thank you very much. 

I'm hosting it on Windows and set PdfRenderer.ReferencePath to the wwwroot folder did the job.

Regards,
Christof


AA Akshaya Arivoli Syncfusion Team February 24, 2020 10:00 AM UTC

Hi Christof, 

Thank you for your update. 

We are glad to know that the reported issue is resolved. Please feel free to revert us if you have any other concerns. We are always happy to assist you. 

Regards, 
Akshaya 



SH sharanya replied to Akshaya Arivoli March 18, 2020 06:21 PM UTC

Hi Christof, 

Thank you for contacting Syncfusion support. 

Based on the provided details 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 Pdfium dll will be generated on runtime within your project location.    
    
However, we have exposed the ReferencePath API to set the pdfium library location path. We can place the pdfium library in project location and refer the project location to the ReferencePath. Please find the below code to set the pdfium location inside the wwwroot folder.   
  
Code snippet:     
 
PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";   
    
Example:    
     
public IActionResult Load([FromBody] Dictionary<stringstring> jsonObject)   
        {   
           PdfRenderer pdfviewer = new PdfRenderer(_cache);   
          PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";   
            MemoryStream stream = new MemoryStream();   
            object jsonResult = new object();   
            if (jsonObject != null && jsonObject.ContainsKey("document"))   
            {   
                if (bool.Parse(jsonObject["isFileName"]))   
                {   
                    string documentPath = GetDocumentPath(jsonObject["document"]);   
                    if (!string.IsNullOrEmpty(documentPath))   
                    {   
                        byte[] bytes = System.IO.File.ReadAllBytes(documentPath);                           
                        stream = new MemoryStream(bytes);   
                    }   
                    else   
                    {   
                        return this.Content(jsonObject["document"] + " is not found");   
                    }   
                }   
                else   
                {   
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]);   
                    stream = new MemoryStream(bytes);   
                }   
            }   
            jsonResult = pdfviewer.Load(stream, jsonObject);   
            return Content(JsonConvert.SerializeObject(jsonResult));   
        }   
     
We have also shared the Pdfium dll in the below link,   
  
 
Note: 
 
Kindly use the  Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux package in your application for linux environment . Also, ensure whether the library dependencies of libpdfium.so are installed properly. If not, please execute the following command to install the dependencies   

RUN apt-get update \     
    && apt-get install -y --allow-unauthenticated \     
        libc6-dev \     
        libgdiplus \     
        libx11-dev \     
        curl \     
        vim \     
        supervisor \     
        procps     
 

 
Please try this and revert us with more details if you are still facing the issue and confirm us whether you are hosting the application in Windows or Linux environment. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 


Same is the issue I'm facing with ASP.NET MVC SyncFusion EJ2. It works in local but not when hosted on server.


AA Akshaya Arivoli Syncfusion Team March 19, 2020 09:12 AM UTC

Hi Sharanya, 

Thank you for contacting Syncfusion support. 

We are unable to reproduce the reported issue, as we mentioned in our previous update, please provide write permission to your project location or use the ReferencePath API to set the pdfium library location path to resolve the reported issue. Please try it and revert us with more details about your issue, sample and hosted environment details. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 



MM Munish Madan May 17, 2020 08:22 PM UTC

Hi. I have the same problem, and have tried the same fix. I am developing on a mac and deploying to Azure AppService. 

I've done quite a bit of troubleshooting to try and determine where the error is occuring and I think your code must be doing some strange multi-threading, because while my logging suggests it is working, the response to the client is the same "initializer threw and exception error". While it works on localhost, it does not work on AppService.

Here is my code: 

[HttpPost("Load")]
public async Task<IActionResult> Load([FromBody] Dictionary<string, string> jsonObject)
{

_logger.LogInformation($"currentDirectory: {Directory.GetCurrentDirectory()}, WebRootPath: {_env.WebRootPath}");

if(!_env.IsDevelopment())
{
// needs a writable location, this is for Azure App Server
// PdfRenderer.ReferencePath = Path.Combine("D:\\local\\Temp");
if (string.IsNullOrWhiteSpace(_env.WebRootPath) || string.IsNullOrEmpty(_env.WebRootPath))
{
_logger.LogInformation($"whoa.. webroot is empty, setting to '{Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")}'");
_env.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
}
PdfRenderer.ReferencePath = _env.WebRootPath;
_logger.LogInformation($"set reference path to '{_env.WebRootPath}'");
}
PdfRenderer pdfviewer = new PdfRenderer(_cache);

_logger.LogInformation($"instanciated PdfRender");
MemoryStream stream = new MemoryStream();
object jsonResult = new object();

_logger.LogInformation($"loading {jsonObject["document"]}");
// put the file from blob service
var fileName = jsonObject["document"];
stream = await _blobService.DownloadBlobAsync(_blobContainerName, fileName);
_logger.LogInformation($"got the stream");
jsonResult = pdfviewer.Load(stream, jsonObject);
_logger.LogInformation($"loaded the stream");
var results = JsonConvert.SerializeObject(jsonResult);
_logger.LogInformation($"serialized the object");
return Ok(results);
}

and here is the logging from AppInsights: 


and here is the response to the client: 

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



AA Akshaya Arivoli Syncfusion Team May 18, 2020 01:21 PM UTC

Hi Munish , 

Thank you for your update. 

Based on the provided details 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 Pdfium dll(libpdfium.dylib) will be generated on runtime within your project location.  So can you please provide read and write permission to that location. If the libpdfium.dylib is not generated manually you can place that dll in wwwroot folder and provide that location in Reference Path. 

We have also shared the Pdfium dll in the below link,    
   

Also please install only the package related to that OS, then build and run the project in that platform. For Windows, Linux and OSX operating systems, use the following corresponding libraries: 

  • Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows
  • Syncfusion.EJ2.PdfViewer.AspNet.Core.Linux
  • Syncfusion.EJ2.PdfViewer.AspNet.Core.OSX

 Please try it and if you still have concerns revert us with more details about issue, environment details , exception/console error details if any. These details will be helpful for us to investigate further and assist you better. 


Regards, 
Akshaya  




BH Balazs Hideghety July 27, 2020 07:22 PM UTC

For debugging consider to use:

public SyncFusionPdfServiceController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;

// https://www.syncfusion.com/forums/151628/the-type-initializer-for-syncfusion-ej2-pdfviewer-pdfiumnative-threw-an-exception

if (!Debugger.IsAttached)
PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";
else
PdfRenderer.ReferencePath = AppDomain.CurrentDomain.BaseDirectory;
}

Also notes:
  1. You don't need the attached DLL's if you use NuGet to install dependencies
  2. Avoid to have both windows/linux versions (linux takes priority over windows) for PDF


AA Akshaya Arivoli Syncfusion Team July 28, 2020 10:59 AM UTC

Hi Balazs, 

Thank you for your update. 

Yes, there is no need to refer the Dll if NuGet packages are referred, also it is enough only the package related to that platform in your project. 

Please revert us with more details if you need any further assistance. 

Regards, 
Akshaya 





MM Michael Martin July 30, 2020 09:30 PM UTC

We are deploying to an azure app service. Including the dll did not solve the issue. What nuget package are you referring to?
Attaching dlls to a build pipleine doesn't seem like a clean approach.

Thanks,

Michael


AA Akshaya Arivoli Syncfusion Team July 31, 2020 12:24 PM UTC

Hi Michael , 

Thank you for your update. 

Please refer to the below link to create PDF Viewer web service project and the list of NuGets with respect to their platforms, 

As  mentioned earlier, 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. Please ensure is there any permission issue in your project, if so the dll will not be generated and the exception occurs. We can resolve it using the ReferencePath API 

Steps to host the web service in Azure app, 


Please try it and revert us with more details about your issue, sample and the error details, if you still have concerns. It will be helpful for us to investigate further and assist you better. 


Regards,  
Akshaya 



TA Tuan Ardouin September 23, 2020 06:33 PM UTC

Hello,

I'm getting the same error when trying to implement your .NET library to load a PDF in a Lambda. 

My code is here :

https://pastebin.com/ZBjAKGYF

I'm still investigation but if you have any tips that would be greatly appreciated.

Tuan


AA Akshaya Arivoli Syncfusion Team September 24, 2020 04:32 PM UTC

Hi Tuan, 

Thank you for your update. 

We suspect that the pdfium dll is not generated in the provided location due to access permission, so the exception occurs. Can you please provide read and write permission to the ‘temp’ folder provided in the ReferencePath. We can also copy and paste the Pdfium dll manually in that location, so it will take the same during run time, 


Also, From the version 17.2.0.39, we have improved the memory cache method in ASP.NET Core. So kindly provide the memory cache in the PdfRenderer () as in this link 
 PdfRenderer pdfviewer = new PdfRenderer(_cache);    
 

Please try it and revert us if you still need further assistance.  

Regards, 
Akshaya  



TA Tuan Ardouin December 23, 2020 03:35 PM UTC

Hello,

It's been a while but I still have the same problem.

I tried to use 

public IMemoryCache _cache;

public Function(IMemoryCache memoryCache)
{
_cache = memoryCache;
}

PdfRenderer pdfviewer = new PdfRenderer(_cache);

But still got :

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

Is it possible to have more logs for this exception ?

I'm pretty sure that I'm not initializing my cache correctly in the Lambda function. If you have an example of it that would be amazing!

Thanks


AA Akshaya Arivoli Syncfusion Team December 24, 2020 01:27 PM UTC

Hi Tuan, 

We have created PDF Viewer web service project and shared the same in the below link, 


Please provide read and write permission to the project location, so that that the pdfium dll is generated during runtime. Also install only the ‘Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows’ packages while working with windows environment. Kindly try these and revert us with more details about your issue and the environment details, if any concerns. 

Regards, 
Akshaya  



TA Tuan Ardouin December 28, 2020 02:41 PM UTC

Hello Akshaya Arivoli,

Thank you for this example, I've already seen it. My problem is that I can't adapt it to a lambda function, because my API run on AWS Gateway.

Do you have an example using the cache functionality using an AWS Lambda function ?

Thank you,
Tuan


AA Akshaya Arivoli Syncfusion Team December 29, 2020 08:56 AM UTC

Hi Tuan , 

Thank you for your update. 

We will create the PDF Viewer web service project in AWS Lamda function and update you with more details on December 31, 2020 

Regards, 
Akshaya  



AA Akshaya Arivoli Syncfusion Team December 31, 2020 02:04 PM UTC

Hi Tuan, 

We are currently working on this with high priority and update you with more details on January 5, 2021. 

Regards, 
Akshaya 



AA Akshaya Arivoli Syncfusion Team January 5, 2021 01:37 PM UTC

Hi Tuan, 

We are facing some issues in including the runtime packages for using the ‘System. Drawing’ in the AWS environment. So we analyzed further and tried to check the package which does not exist in the AWS environment by enabling the LD_DEBUG to libs and then the message we have retrieved in the stack trace is “trying to find Microsoft.DiaSymReader.Native.amd64.dll”. So, we manually copied the dll and published the same, but still, the same issue occurs. We have raised the question in the AWS forum regarding the issue faced on our end. We will update you once the solution is provided in the forum.  



Regards, 
Akshaya 



TA Tuan Ardouin January 5, 2021 02:10 PM UTC

Hello,

Thank you very much for the update! 

Can you share the code you used for the lambda ? I'm going to create a ticket with the business support.

Thank you,
Tuan


DM Dhivyabharathi Mohan Syncfusion Team January 6, 2021 11:22 AM UTC

Hi Tuan, 
 
We have shared the modified sample in which we have tried to convert the PDF page to image by using our ExportAsImage() functionality. Please find the modified sample in the below link 
 
 
Regards, 
Dhivya. 



TA Tuan Ardouin January 8, 2021 10:01 AM UTC

Hello, 

Did you see those 2 issues :

https://github.com/aws/aws-lambda-dotnet/issues/516

https://github.com/aws/aws-lambda-dotnet/issues/716

And to be perfectly clear, what I'm trying to do is create the API used by the VueJS pdf viewer in the serviceUrl. So I'll need more than a lambda that convert a pdf to an image. I need the /load /renderPdfPages ...

Also, the pdf will come from S3, not from the current path. Here is my current lambda function :

https://pastebin.com/U72NnFAd

Tuan


AA Akshaya Arivoli Syncfusion Team January 11, 2021 12:58 PM UTC

Hi Tuan, 

A support incident to track the status of reported issue has been created under your account. Please log on to our support website to check for further updates.     
  

Please let us know if you have any concern on this. 

Regards, 
Akshaya  



TA Tuan Ardouin January 13, 2021 06:37 PM UTC

Hello,

I have No support incidents are associated with your account.

Should I do something ?


HA Harry replied to Akshaya Arivoli January 11, 2022 02:58 PM UTC

Hello, I am facing similar issues getting the PdfViewer to work in AWS Lambda. Do you have any updates on this? Thanks



DM Dhivyabharathi Mohan Syncfusion Team January 12, 2022 02:49 PM UTC

Hi Harry, 
 
 
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, 
 
 
 
 
Regards, 
Dhivya. 



JA John Anton January 24, 2022 12:28 PM UTC

I have tried these steps in deploying the server to Google App Engine with no luck. 



DM Dhivyabharathi Mohan Syncfusion Team January 27, 2022 06:46 AM UTC

Hi John, 
 
 
Could you please let us know the exact issue which you are facing on your end while hosting the application in the server. And kindly share the steps which you have tried and screenshot of the issue which you are facing. So that it will be helpful for us to investigate further and assist you better. 
 
 
Regards, 
Dhivya. 



MA Matthew April 15, 2022 11:12 PM UTC

I am also receiving this issue.  I have a blazor wasm client and webapi.


                

                jsonResult = pdfviewer.Load(stream, jsonObject);
                var content = JsonConvert.SerializeObject(jsonResult);
                b.AppendLine($"jsonResult: {content}");
                return Content(content);


My files are located on a network path.  They cannot be mounted to the IIS application.  I am looking to simply load the bytes and send them back to the client, a stream or other chunking solution would be preferred.

Logging this out to my event log clearly shows that I load the bytes.  However; the serialization operation fails with the error: "The type initializer for 'Syncfusion.EJ2.PdfViewer.PdfiumNative' threw an exception."

 public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)
        {
            StringBuilder b = new StringBuilder();


            try
            {
                Console.WriteLine("Load called");
                //Initialize the PDF viewer object with memory cache object
                PdfRenderer pdfviewer = new PdfRenderer(_cache);


                if (!Debugger.IsAttached)
                    PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";
                else
                    PdfRenderer.ReferencePath = AppDomain.CurrentDomain.BaseDirectory;


                MemoryStream stream = new MemoryStream();
                object jsonResult = new object();
                if (jsonObject != null && jsonObject.ContainsKey("document"))
                {
                    b.AppendLine("Contains key 'document'.");
                    if (bool.Parse(jsonObject["isFileName"]))
                    {
                        b.AppendLine("is a file name");
                        string documentPath = GetDocumentPath(jsonObject["document"]);
                        b.AppendLine($"working with file: {documentPath}");
                        b.AppendLine($"documentPath isnull = {string.IsNullOrEmpty(documentPath)}, exists = {System.IO.File.Exists(documentPath)}");


                        if (!string.IsNullOrEmpty(documentPath) && System.IO.File.Exists(documentPath))
                        {
                            byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
                            b.AppendLine($"byteCount: {bytes.Length}");
                            stream = new MemoryStream(bytes);
                        }
                        else
                        {
                            b.AppendLine($"unable to find: {documentPath}");
                            throw new FileNotFoundException("document no found.");
                            //return this.Content(jsonObject["document"] + " is not found");
                        }
                    }
                    else
                    {
                        b.AppendLine($"is not a file name");
                        byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
                        stream = new MemoryStream(bytes);
                    }
                }
                jsonResult = pdfviewer.Load(stream, jsonObject);
                var content = JsonConvert.SerializeObject(jsonResult);
                b.AppendLine($"jsonResult: {content}");
                return Content(content);
            }
            catch (FileNotFoundException)
            {
                b.AppendLine($"error file not found.");
                return this.Content($"The documentId: {jsonObject["document"]} was not found.");
            }
            catch (ArgumentOutOfRangeException)
            {
                b.AppendLine($"error argument out of range.");
                return this.Content($"The documentId: {jsonObject["document"]} is an invalid document identifier.");
            }
            catch (Exception ex)
            {
                b.AppendLine($"error unexpected.\r\n{ex.Message}");
                return this.Content($"An unexpted error occurred loading {jsonObject["document"]}.");
            }
            finally {
                _logger.LogWarning($"Load Document Actions:\r\n{b}");
            }
        }


The event log out is:


Load Document Actions:

  Contains key 'document'.

  is a file name

  working with file: \\NCC-1701\File Services\Warehouses\TSCC\00000000\5abb3271afb94061bf55db1334816282.pdf

  documentPath isnull = False, exists = True

  byteCount: 81885

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






VS Vasugi Sivajothi Syncfusion Team April 18, 2022 01:24 PM UTC

Hi Matthew,


We suspect that issue is due to pdfium.dll is not referred properly. 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 ?
 
 

https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfium956869027.zip   


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:/";    


Steps to refer the Pdfium.dll:

1.Extract the given file (Pdfium folder) and copy it in the sample’s root directory (parallel to Controllers folder)  

2. Right-click on the pdfium.dll (both the X64 andX86 folder) and then choose the “Copy to Output Directory” property from the property window and set its value to “copy always”. This setting will ship the pdfium.dll assembly to the published location.   


Screenshot:   



3. Provide this path in the Load method of the PDFViewerController.cs     

Note: You need to refer the ParentFolder up to x64/x86 folder.  

 

PdfRenderer.ReferencePath = _hostingEnvironment.ContentRootPath + \\Pdfium\\ 


4. Build and publish the application.  

Also please install only the package related to that OS, then build and run the project in that platform. For Windows, Linux and OSX operating systems, use the following corresponding libraries: 


Kindly try this and let us know if the issue resolves or not.


Regards,

Vasugi



MA Matthew replied to Vasugi Sivajothi April 22, 2022 03:43 PM UTC

This worked as expected.  Thanks.



CL Clay November 28, 2022 02:31 AM UTC

Hello,


I am an intern developer who is very new to .NET but am having a very similar issue to this one and have tried everything mentioned in the thread and it has worked great for me on Windows but not my Mac. I have set the ReferencePath to /Pdfium/ relative to content root, and have folders x64/ and x86/, each with the correct .dll files. As well I have installed Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows (all of this on Windows) and it works. On Mac, I have an ARM processor which is likely the issue but I am unsure of how to proceed. I have similar x64/ and x86/ folders with the provided libpdfium.dylib in both folders, as well as Syncfusion.EJ2.PdfViewer.AspNet.Core.OSX installed, and the Windows package removed. When I start the local server and PdfRenderer.ReferencePath gets set, it creates a NEW folder 'x64\' inside of /Pdfium/ that generates pdfium.dll inside of it, and I assume that my Mac cannot read this file, and possibly can't even access the folder. I am wondering either if there is a way for me to force PdfRenderer to recognize the x64 folder that already exists or if I can change something such that the generated file is correct for my platform.


Apologies if anything I've mentioned is obviously solved or if I'm asking the wrong questions. I'm very new to this and would greatly appreciate any help, as it is difficult for me to consistently work on Windows and I'd much prefer to develop on my Mac.


Thank you,

Andrew



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team November 28, 2022 01:24 PM UTC

Currently, there is no support for ARM64 in the PDF Viewer component. We have already logged a feature request as “PDF Viewer should work in .NET 6.0 ARM64 on the Linux Platform”. But we don’t have immediate plans to implement this feature and it will be available in any of our future releases in 2023. You can track the status of the feature through the following link.


Feedback link:  PDF Viewer should work in .NET 6.0 ARM64 on the Linux platform | Feature Feedback



IS Ifra Saleem April 2, 2024 09:02 AM UTC

I'm encountering an error while working with the ASP.NET Core PDF Viewer Web Service example provided by Syncfusion. The error message I'm seeing is:

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

I've followed the instructions provided in the GitHub repository (https://github.com/SyncfusionExamples/EJ2-PDFViewer-WebServices/tree/main/ASP.NET%20Core/PdfViewerWebService_8.0) to set up the project and also followed the instruction given in this thread and Pdfium dll is generating on runtime within my project location (/EJ2-PDFViewer-WebServices/ASP.NET Core/PdfViewerWebService_8.0/PdfViewerWebService_8.0/wwwroot\/x64\/libpdfium.so)

. but I'm unable to resolve this issue.

Code:


publicIActionResultLoad([FromBody] Dictionary<string, string> jsonObject)

{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
PdfRenderer.ReferencePath = _hostingEnvironment.WebRootPath + "\\";
MemoryStream stream = new MemoryStream();
object jsonResult = new object();
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
if (bool.Parse(jsonObject["isFileName"]))
{
string documentPath = GetDocumentPath(jsonObject["document"]);
if (!string.IsNullOrEmpty(documentPath))
{
byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
stream = new MemoryStream(bytes);
}
else
{
return this.Content(jsonObject["document"] + " is not found");
}
}
else
{
byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
stream = new MemoryStream(bytes);
}
}
jsonResult = pdfviewer.Load(stream, jsonObject);
return Content(JsonConvert.SerializeObject(jsonResult));
}


CK Chinnamunia Karthik Chinna Thambi Syncfusion Team April 3, 2024 01:38 PM UTC

Hi Ifra,


We recommend using the "Syncfusion.EJ2.PdfViewer.AspNet.Core"NuGet package, which is compatible with Windows, Linux, and OSX platforms and also, please remove the Reference path and try once.

 

If you are using the PDF Viewer with Docker in .NET 6.0 framework, please refer to the following Dockerfile and modify your Dockerfile accordingly:

 

 

If you are using the PDF Viewer with Docker in .NET 8.0 framework, please refer to the following Dockerfile and modify your Dockerfile accordingly:

 

 

If you are still facing any issues, please provide the following details, which will help us analyze further and provide assistance:

 

  • Hosted environment (Windows, Linux, or Mac) and the steps for deploying the application (using Docker or any other method).
  • Whether you are rendering the component inside a Docker container.
  • .NET framework versions.
  • If possible, provide a sample in which the reported issue occurred.


SP Saurabh Pabhare replied to Akshaya Arivoli April 8, 2024 05:05 PM UTC

Hello! I am facing similar issues getting the PdfViewer to work in AWS Lambda. Do you have any updates on this? 

Thanks



CK Chinnamunia Karthik Chinna Thambi Syncfusion Team April 9, 2024 03:42 PM UTC

Hi Saurabh,


Based on the given details, we suspect that the Pdfium dependency is not installed in your environment. Please follow below steps to install the Pdfium dependency:


  • If you are using the docker, kindly compare the below docker file and modify your docker file accordingly.



  • If you using the VM, Please use the below commands to install the Pdfium dependency.


 

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


Loader.
Up arrow icon