需要開啟pdf檔案時,我們第一印象就是使用adobe reader。在開發中,經常會遇到需要展示pdf檔案的需求。我們會借助於adobe reader的active控制項來實現。不過這需要客戶的機器上安裝有adobe reader,並且使用adobe reader的active控制項會在頂部有乙個隱藏不了的工具欄。這樣顯然不合理。
在github上看到乙個非常好的wpf中承載pdf檔案的類庫。
1. 工程中新增對moonpdflib.dll的引用,另外記得將libmupdf.dll放置於wpf工程bin檔案下。
2. **:
xaml:
<c#:window
x:class
="wpfpdfviewer.mainwindow"
xmlns
=""xmlns:x
=""xmlns:d
=""xmlns:mc
=""xmlns:mpp
="clr-namespace:moonpdflib;assembly=moonpdflib"xmlns:local
="clr-namespace:wpfpdfviewer"
mc:ignorable
="d"
title
="wpf pdf viewer"
height
="350"
width
="525"
>
<
grid
>
<
grid.rowdefinitions
>
<
rowdefinition
height
="auto"
/>
<
rowdefinition
height
="*"
/>
grid.rowdefinitions
>
<
border
background
="#f0f0f0"
>
<
stackpanel
horizontalalignment
="left"
orientation
="horizontal"
>
<
button
content
="檔案"
width
="50"
click
="filebutton_click"
margin
="5,5"
/>
<
button
content
="放大"
width
="50"
click
="zoominbutton_click"
margin
="0,5"
/>
<
button
content
="縮小"
width
="50"
click
="zoomoutbutton_click"
margin
="5,5"
/>
<
button
content
="100%"
width
="50"
click
="normalbutton_click"
margin
="0,5"
/>
<
button
content
="整頁"
width
="50"
click
="fittoheightbutton_click"
margin
="5,5"
/>
<
button
content
="單頁"
width
="50"
click
="singlepagebutton_click"
margin
="0,5"
/>
<
button
content
="雙頁"
width
="50"
click
="facingbutton_click"
margin
="5,5"
/>
stackpanel
>
border
>
<
border
background
="#d3d3d3"
grid.row
="1"
><
mpp:moonpdfpanel
x:name
="moonpdfpanel"
background
="lightgray"
viewtype
="singlepage"
pagerowdisplay
="continuouspagerows"
pagemargin
="0,2,4,2"
allowdrop
="true"
/>
border
>
grid
>
window
>
public partial class mainwindow : window3. 執行程式,開啟pdf檔案,private void filebutton_click(object sender, routedeventargs e)
catch (exception)}}
private void zoominbutton_click(object sender, routedeventargs e)
}private void zoomoutbutton_click(object sender, routedeventargs e)
}private void normalbutton_click(object sender, routedeventargs e)
}private void fittoheightbutton_click(object sender, routedeventargs e)
private void facingbutton_click(object sender, routedeventargs e)
private void singlepagebutton_click(object sender, routedeventargs e)
}
moonpdf的原理是將pdf檔案轉成了檔案,然後再顯示出來的。moonpdf的開發者在codeplex上的這篇文章介紹了moonpdf了,非常不錯。
WPF 瀏覽PDF 檔案
新增成功後會在工具箱裡看到下圖所示的控制項。開啟vs2010,新建專案 wpfpdfreader 右鍵專案新增user control 使用者控制項 因為adobe pdf reader com 元件是不支援wpf的,為此我們需要將它放到winform 控制項中。所以,在列表中需要選擇user co...
Android 檢視pdf文件 PDFView
最近在搞android顯示word文件跟pdf文件的顯示,分享乙個顯示pdf文件的小demo ps word文件的顯示網上挺多的 public class mainactivity extends activity pdfnameall urlpath.substring urlpath.lasti...
PDF預覽 pdfJS預覽pdf檔案
方式1 檔案流轉為blob let urlsrc window.url.createobjecturl blob this src urlsrc pdf空白頁 else 正確解析了頁碼,但是每頁空白。解決方法 responsetype blob html visible.sync dialo isi...