WPF:WPF显示PDF文档
2021-06-28 16:06
标签:source use back express tac ges text 51cto 100% ??软件的帮助文档可借助第三方软件如PDF Reader、Adobe PDF等显示,但客户机上需安装此类软件。WPF开发的软件可借助第三方库 MoonPdf 将PDF文档加载显示到软件窗口中(Dll下载地址,GitHub源码地址)。 PDFViewer.xaml PDFViewer.cs 调用PdfViewer,及HelpWin窗口类:HelpWin.xaml HelpWin.cs WPF:WPF显示PDF文档 标签:source use back express tac ges text 51cto 100% 原文地址:http://blog.51cto.com/weiyuqingcheng/2323929MoonPdf库使用方式:
代码
using MoonPdfLib; //记得引用此命名空间
public partial class PdfViewer : UserControl
{
private bool m_bLoaded = false;
public PdfViewer()
{
InitializeComponent();
}
public bool LoadPdfDoc( string strPdfPath )
{
try
{
this.pdfViewer.OpenFile( strPdfPath );
this.pdfViewer.Zoom( 1.0 );
m_bLoaded = true;
}
catch
{
m_bLoaded = false;
}
return m_bLoaded;
}
private void ZoomToOrigin_Click( object sender, RoutedEventArgs e )
{
if ( !m_bLoaded )
return;
this.pdfViewer.Zoom( 1.0 );
}
private void SinglePage_Click( object sender, RoutedEventArgs e )
{
if ( !m_bLoaded )
return;
this.pdfViewer.ViewType = ViewType.SinglePage;
}
private void DoublePage_Click( object sender, RoutedEventArgs e )
{
if ( !m_bLoaded )
return;
this.pdfViewer.ViewType = ViewType.Facing;
}
}
public partial class HelpWin : Window
{
private string m_strPdfPath = AppDomain.CurrentDomain.BaseDirectory + "help.pdf";
public HelpWin()
{
InitializeComponent();
}
private void ImgClose_MouseDown( object sender, MouseButtonEventArgs e )
{
this.Close();
}
private void PDFView_Loaded( object sender, RoutedEventArgs e )
{
if ( !this.PDFView.LoadPdfDoc( m_strPdfPath ) )
{
MessageBox.Show( "打开帮助文档失败,请重试!" );
}
}
}
效果