在 .NET 下使用 Pdfium 渲染和打印 PDF
大家可能已經看到這條 新聞,Google最近又新推出一個開源項目,名叫 PDFium,將成為Chrome瀏覽器的PDF渲染引擎組件。與已有的開源PDF引擎如Firefox目前的PDF解決方案PDF.js以及 Poppler相比,PDFium性能要好得多。
本次開源是由Google方面主導的,因為Chrome里的PDF渲染使用的是福昕的專有技術授權,Google方面希望能夠開源並提出了很好的條件。福昕從長遠考慮,接受了Google的建議。
接下來,福昕仍然會繼續投入技術力量支持PDFium的發展。我們已經在PDFium項目網站上看到Bo Xu等三名福昕工程師在 解決和解答各種問題。
官方的 API 文檔:https://developers.foxitsoftware.com/resources/pdf-sdk/c_api_reference_pdfium/index.html
一個 PDF 版本的 Pdfium API 文檔:http://cdn01.foxitsoftware.com/pub/foxit/manual/enu/FoxitPDF_SDK20_Guide.pdf
許可協議:Apache 2.0 見:https://pdfium.googlesource.com/pdfium/+/refs/heads/master/LICENSE
來源:https://www.csdn.net/article/2014-06-23/2820351-Why-Foxit-Open-Sourced-Core-PDF-technologies
Pdfium 庫
Pdfium 本身是一個 C 語言庫,編譯之后是一個 DLL。
Google 下載
https://pdfium.googlesource.com/pdfium/
GitHub
https://github.com/chromium/pdfium
下載 Pdfium 二進制預編譯庫
可以直接使用預編譯的庫,既可以直接從 NuGet 中導入,也可以自己下載使用。
NuGet
下面這兩個比較版本比較老。
https://www.nuget.org/packages/PdfiumViewer.Native.x86_64.no_v8-no_xfa/
Native 64-bit PDFium DLL without V8 or XFA support for usage with the PdfiumViewer project.
2018.4.8.256
https://www.nuget.org/packages/PdfiumViewer.Native.x86.no_v8-no_xfa/
Native 32-bit PDFium DLL without V8 or XFA support for usage with the PdfiumViewer project.
2018.4.8.256
GitHub
這個比較新
GitHub: https://github.com/bblanchon/pdfium-binaries
PdfiumViewer
由於 Pdfium 本身並不是 .NET 庫,在 .NET 中使用時,需要進行適配,PdfiumViewer 對它進行了適配工作,可以使我們很方便地在 .NET 項目中使用它。
Introduction
PdfiumViewer is a PDF viewer based on the PDFium project.
- PdfiumViewer provides a number of components to work with PDF files:
- PdfDocument is the base class used to render PDF documents;
- PdfRenderer is a WinForms control that can render a PdfDocument;
PdfiumViewer 提供了一個 WinForms 控件,通過 PdfRenderer 控件進行渲染,提供了工具欄,可以支持保存到 PDF 文件或者打印到打印機。
PdfiumViewer is a WinForms control that hosts a PdfRenderer control and adds a toolbar to save the PDF file or print it.
項目:https://github.com/pvginkel/PdfiumViewer
NuGet: https://www.nuget.org/packages/PdfiumViewer/
參考
- https://www.foxitsoftware.com/blog/foxit-pdf-technology-chosen-for-google-open-source/
- https://www.foxitsoftware.com/blog/the-interesting-history-and-fascinating-future-of-pdf-software/
- https://github.com/chromium/pdfium/blob/master/public/fpdf_transformpage.h
- https://github.com/datalogics/adobe-pdf-library-samples/blob/master/DotNET/Sample_Source/Images/RasterizePage/RasterizePage.cs
- https://github.com/chromium/pdfium/blob/master/core/fpdfapi/page/cpdf_page.cpp