使用DevExpress的PdfViewer实现PDF打开、预览、另存为、打印(附源码下载)

场景

Winform控件-DevExpress18下载安装注册以及在VS中使用:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243

参照以上将DevExpress安装并引进到工具箱。

这里使用的是VS2013所以安装的DevExpress是14版本。

DevExpress14以及注册机下载


https://download.csdn.net/download/badao_liumang_qizhi/11608734

效果

 

实现

项目搭建

新建winfom程序,然后拖拽一个Pdfvieerr控件。然后添加一个Button按钮。

 

PDF打开与预览实现

双击进入Button按钮的点击事件中

 private void simpleButton2_Click(object sender, EventArgs e)
        {
            //打开pdf文件,并获取文件路径
            string filePath = FileDialogHelper.OpenPdf();
            //如果不为空
            if (!string.IsNullOrEmpty(filePath))
            {
                //加载预览  其中pdfViewer1 与控件的name相对应
                this.pdfViewer1.LoadDocument(filePath);
            }
        }

然后新建FileDialogHelper工具类,实现选择打开文件并返回路径的功能。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PDFExport
{
    class FileDialogHelper
    {
        public static string OpenPdf() {
       
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*pdf*)|*.pdf*"; //设置要选择的文件的类型
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                return fileDialog.FileName;//返回文件的完整路径               
            }
            else {
                return null;
            }

        }
    }
}

PDF另存为实现

在窗体上再拖拽一个Button,双击进入其点击事件中。 

private void simpleButton1_Click_1(object sender, EventArgs e)
        {

            this.pdfViewer1.SaveDocument(@"D:\PDF\A.pdf");
        }

注:

调用自带的SaveDocument()方法,这里传递的是保存的路径。

其还有个重载方法:

public void SaveDocument(Stream stream);

效果

 

 

 

 

打印PDF实现

再拖拽一个按钮,双击进入其点击事件中。

 private void simpleButton3_Click(object sender, EventArgs e)
        {
            this.pdfViewer1.Print();
        }

效果

 

源码下载

https://download.csdn.net/download/badao_liumang_qizhi/11617199


 

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霸道流氓气质

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值