ToB企服应用市场:ToB评测及商务社交产业平台

标题: .Net PdfiumViewer 打印时无法渲染电子署名问题的解决方法 [打印本页]

作者: 千千梦丶琪    时间: 2024-10-14 16:17
标题: .Net PdfiumViewer 打印时无法渲染电子署名问题的解决方法
转载请标明原出处:https://www.cnblogs.com/crpfs/p/18463735
1. 先决条件

本文修改的动态库是从如下的 NuGet 包中获取的:
假如利用的是 Visual Studio 中的 NuGet 包管理器获取的,则其动态库(.dll)一样平常会存放在:
  1. .\packages\PdfiumViewer.2.13.0.0\lib\net20\PdfiumViewer.dll
复制代码
另外,还必要反编译动态库的工具:dnSpy,本文利用的是 dnSpy 作者弃坑后另一位佬接手重生的项目 dnSpyEx

2. 解决方法

① 将动态库拖入 dnSpy,展开如下命名空间:
② 找到 PdfPrintDocument 类,展开,再找到 RenderPage 方法:
③ 右键 ==> 修改方法(C#),修改最后一行代码:
  1. // 原本的代码
  2. // this._document.Render(page, e.Graphics, e.Graphics.DpiX, e.Graphics.DpiY, new Rectangle(PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiX, left), PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiY, top), PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiX, num3), PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiY, num4)), PdfRenderFlags.ForPrinting | PdfRenderFlags.Annotations);
  3. // 修改后的代码
  4. using (Image image = this._document.Render(page, PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiX, (double)e.PageBounds.Width), PdfPrintDocument.AdjustDpi((double)e.Graphics.DpiX, (double)e.PageBounds.Height), e.Graphics.DpiX, e.Graphics.DpiY, PdfRotation.Rotate0, PdfRenderFlags.ForPrinting | PdfRenderFlags.Annotations))
  5. {
  6. e.Graphics.DrawImageUnscaled(image, e.PageBounds.Location);
  7. }
复制代码
④ 在菜单栏选择 文件 ==> 生存模块,直接点确定即可重新编译动态库。
注意:会直接覆盖原先的动态库,如必要则注意备份。


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4