Search code examples
c#syncfusionpdfium

Loading unmanaged dll without writing it to disk


We are using Syncfusion.PdfViewer.WPF for displaying PDFs. From version 16.1.0.24 it is using Pdfium for rendering. It has unmanaged pdfium.dll embeded in dll, and at runtime it is unpacked to application folder. This does not work when application is installed since users do not have write access to c:/Program Files/.

Is there a way to load those dlls without writing them to disk first?

Extracting them from dll and loading using Assembly.Load does not work since it is unmanaged dll.


Solution

  • From 16.3 version, Pdfium dlls are embedded in the PdfViewer assemblies and the Pdfium dlls will be extracted in the application folder at the run-time to render complex shapes, images, and text without any flaws. If the application folder does not have write permission, the reported exception may occur. But it is not necessary that the application path should always have write permission and you can resolve the reported error from sample level with any of the below solutions.   

    Solution 1: From the 16.3 versions, you need to add the below code snippet in the sample level to change the rendering engine to use SfPdf rendering engine as well as avoid generating Pdfium dlls in the application folder. 

    PdfDocumetView pdfDocumentView = new PdfDocumentView();  
    pdfDocumentView.RenderingEngine = 
    Syncfusion.Windows.Forms.PdfViewer.PdfRenderingEngine.SfPdf;  
    pdfDocumentView.Load("Sample.pdf");  
    

    Solution 2:  If you need to use Pdfium rendering engine as well as avoid generating the Pdfium dlls in the write permission restricted folder. You can redirect the extraction of Pdfium assemblies in the custom path in which the write permission is granted by setting the ReferencePath property. 

    PdfDocumetView pdfDocumentView = new PdfDocumentView();  
    pdfDocumentView.ReferencePath = @"D:\ReferencePath\";  
    pdfDocumentView.Load("Sample.pdf");  
    

    Note: In the run time, PDF viewer will check the custom path provided in the ReferencePath property. If you already placed the Pdfium dlls in the custom path as mentioned in the UG link (https://help.syncfusion.com/windowsforms/pdfviewer/how-to/use-pdfium-rendering-engine), it will refer the already available dlls from the location without generating the dlls. 

    Regards,

    Uthandaraja S(I work for Syncfusion)