1:簡介
PdfiumViewer 是一個 WinForms 控件,它承載一個 PdfRenderer 控件并添加一個工具欄來儲存或列印 PDF 檔案
2:相容性
除了正常的win7 win10 也支援xp win8
3:對比Spire.Pdf和Adobe PDF Reader
Spire.Pdf收費且免費版隻能列印三頁的pdf
Adobe PDF Reader每台電腦都必須要安裝Adobe PDF 客戶體驗不太好
PdfiumViewer開源且免費 預覽列印文檔内容無上限
4:安裝使用
使用Nuget搜尋pdfiumviewer安裝
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiMGc902byZ2PkRmNzEjZjZWMwMjMmlDM5AzM3QDNxMTYzIzMlJmN4Y2LcBza5QTcsJja2FXLp1ibj1ycvR3Lc5Wanlmcv9CXt92YucWbp9WYpRXdvRnL2A3Lc9CX6MHc0RHaiojIsJye.jpg)
準備一個pdf檔案
我這裡找了一個wpf書籍一共有900多頁
界面上添加一個PdfViewer控件和一個button按鈕
按鈕裡面的事件
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.Title = "打開pdf檔案";
ofd.Filter = "pdf檔案(*.pdf)|*.pdf";
ofd.ShowDialog();
string path = ofd.FileName;
pdfViewer1.Document = OpenDocument(path);
}
private PdfDocument OpenDocument(string fileName)
{
try
{
return PdfDocument.Load(fileName);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
運作起來打開我們的pdf書籍,可以看到我們的預覽效果
然後檢視我們的放大縮小儲存和列印事件都是封好了的,不用自己去寫代碼
列印事件也很好用
最後我希望所有neter關注前沿技術,不要故步自封。
最後大家如果喜歡我的文章,還麻煩給個關注, 希望net生态圈越來越好!