加载非托管 dll 而不将其写入磁盘

Loading unmanaged dll without writing it to disk

我们正在使用 Syncfusion.PdfViewer.WPF 来显示 PDF。从版本 16.1.0.24 开始,它使用 Pdfium 进行渲染。它在 dll 中嵌入了非托管 pdfium.dll,并且在运行时将其解压缩到应用程序文件夹。这在安装应用程序时不起作用,因为用户没有对 c:/Program Files/ 的写入权限。

有没有办法加载这些 dll 而无需先将它们写入磁盘?

从 dll 中提取它们并使用 Assembly.Load 加载不起作用,因为它是非托管 dll。

从 16.3 版本开始,Pdfium dll 嵌入到 PdfViewer 程序集中,Pdfium dll 将在 运行 时提取到应用程序文件夹中,以毫无瑕疵地呈现复杂的形状、图像和文本。如果应用文件夹没有写入权限,可能会出现报错。 但应用程序路径不必始终具有写入权限,您可以使用以下任何解决方案从示例级别解决报告的错误。

解决方案一:从16.3版本开始,需要在sample级别添加以下代码片段,将渲染引擎改为使用SfPdf渲染引擎,同时避免生成应用程序文件夹中的 Pdfium dll。

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

解决方案2:如果您需要使用Pdfium渲染引擎并且避免在写权限受限的文件夹中生成Pdfium dll。您可以在自定义路径中重定向 Pdfium 程序集的提取,通过设置 ReferencePath 属性 授予写权限。

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

注意:在运行时,PDF查看器会检查ReferencePath中提供的自定义路径属性.如果您已经将 Pdfium dll 放置在 UG link (https://help.syncfusion.com/windowsforms/pdfviewer/how-to/use-pdfium-rendering-engine) 中提到的自定义路径中,它将从该位置引用已经可用的 dll 而不会生成 dll。

此致,

Uthandaraja S(我为 Syncfusion 工作)