C#winform打印pdf
钢翼
编程
最近找C#winform上打印pdf的组件,找了几个都不太理想,记录下。
1.aspose.pdf 收费,本机没有字体时打印会出现方格,而且当pdf的字体是付费时,下载安装字体可能会更麻烦。
var pdfViewer = new PdfViewer(); pdfViewer.BindPdf(fileName); // Render all system fonts with native system approach (embed the fonts to output documents) pdfViewer.RenderingOptions.SystemFontsNativeRendering = true; pdfViewer.AutoRotate = true;//自动旋转 pdfViewer.PrintDocument(); pdfViewer.Close();
2.使用pdfiumViewer打印,打印时没有电子签章
var pdfDocument = PdfDocument.Load(fileName); printDocument = pdfDocument.CreatePrintDocument(); printDocument.DocumentName = pdfDocument.PageCount.ToString(); printDocument.PrintController = new StandardPrintController();//屏蔽打印窗 printDocument.Print();
好在pdfiumViewer是开源的,调试下,发现是调用pdfium.dll的FPDF_RenderPage方法,无论模式是否FPDF.ANNOT,都不显示电子签章。
既然显示可以,那么换个思路,打印的时候通过pdfium.dll的FPDF_RenderPageBitmap获取图片,直接绘制打印是否就解决了。
修改后的github地址:https://github.com/wmz46/PdfiumViewer