一、PDFium官網
PDFium是一個針對Google Chrome瀏覽器的PDF閱讀器引擎,它的源代碼開放,採用了MIT License協議。我們可以在官網對PDFium進行下載,這裡提供了Windows和Linux的下載地址。
例如:https://pdfium.googlesource.com/pdfium/+/refs/tags/chromium/4280/windows/
在官網的源碼下載頁面,我們可以找到PDFium的代碼,其中包括了子模塊的更新命令、編譯命令和文檔等。
二、PDFiumViewer
PDFiumViewer是在PDFium引擎上開發的PDF閱讀器,它適用於Windows Vista及以上版本。PDFiumViewer以nuget添加到你的項目中。
下面是一個簡單的PDFiumViewer的代碼示例:
using PdfiumViewer; using System.Drawing; using System.Windows.Forms; namespace Example { public partial class FrmPdfViewer : Form { public FrmPdfViewer() { InitializeComponent(); using (var docStream = MyApp.GetPdfStream()) { this.pdfViewer.Load(docStream); } } } }
三、PDFium閱讀器
PDFium閱讀器是一個基於PDFiumViewer的C#控制項,它由VBForums的開發者Bob Powell創建。該控制項能夠在你的WinForms應用程序中,輕鬆地顯示PDF文件。
下面是一個PDFium閱讀器的代碼示例:
using PdfiumViewer; using System.Drawing; using System.Windows.Forms; namespace Example { public partial class FrmPdfViewer : Form { public FrmPdfViewer() { InitializeComponent(); using (var docStream = MyApp.GetPdfStream()) { pdfDisplay.Load(docStream); pdfDisplay.ZoomMode = PdfViewerZoomMode.FitHeight; } } } }
四、PDFium 介面說明
PDFium提供了一些重要的介面,可以供你使用,下面是一些代碼示例:
- 載入PDF文件:
FPDF_LoadDocument(path, password);
FPDF_GetPageCount(document);
FPDF_GetPageHeight(page);
FPDF_GetPageWidth(page);
FPDF_RenderPage(dc, page, startX, startY, width, height, 0, FPDF_ANNOT, FPDF_LCD_TEXT);
五、PDFium.dll
PDFium.dll是由PDFium提供的PDF解析庫,它可以讓我們完成PDF渲染、搜索和交互等功能。它對於Windows應用程序的開發特別有用。如果你出現了PDFium.dll丟失的情況,你可以到這裡下載並安裝Microsoft Visual C++ 2010 Redistributable Package。
六、PDFium.dll丟失怎麼辦
如果PDFium.dll丟失了,你可以在Windows目錄中,添加PDFium.dll或者在你的程序目錄中添加PDFium.dll文件。例如:
[DllImport("pdfium.dll", CharSet = CharSet.Unicode)] extern static IntPtr FPDF_LoadMemDocument(byte[] data_buf, int size, string password);
七、PDFiumViewer幫助文檔
PDFiumViewer提供了一些幫助文檔,可以協助我們更好的掌握PDFium,這些文檔包括在PDFiumViewer安裝包中,也可以在官網上下載。
例如:https://github.com/pvginkel/PdfiumViewer/wiki/Getting-started
結語
PDFium作為一個PDF閱讀器引擎,它的代碼開放,應用場景廣泛,憑藉著自身的優異性能和易用性,如今已經成為了開發者們必備的工具之一。希望通過本篇文章的介紹,對於PDFium有更深入的了解。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/279106.html