基本信息
源码名称:PDF分割、合并、旋转、加密小工具
源码大小:0.22M
文件格式:.7z
开发语言:C#
更新时间:2019-06-04
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

对PDF文件进行加密、分割、合并。




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


namespace PDFMergeAndSplitTool
{
    public partial class PDFCtrl : Form
    {
        public PDFCtrl()
        {
            InitializeComponent();
        }
        private void btnSplit_Click(object sender, EventArgs e)
        {
            OpenFileDialog opflDlg = new OpenFileDialog();
            opflDlg.Title = "选择需拆分的pdf文件(可多选)";
            opflDlg.Filter = "PDF Files | *.pdf;*.PDF";
            opflDlg.Multiselect = true;
            if (opflDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> selectFiles = opflDlg.FileNames.ToList();
                FolderBrowserDialog folderDialog = new FolderBrowserDialog();
                folderDialog.Description = string.Format("请选择保存路径!\n用于保存分割文件");
                if (folderDialog.ShowDialog() == DialogResult.OK)
                {
                    string filePath = folderDialog.SelectedPath;
                    selectFiles.ForEach(
                        file =>
                        {
                            YFASC_PDF.Instance.SplitPDF(file, filePath);
                        });
                }
            }
        }
        private void btnMerge_Click(object sender, EventArgs e)
        {
            OpenFileDialog opflDlg = new OpenFileDialog();
            opflDlg.Title = "选择需合并的pdf文件(可多选)";
            opflDlg.Filter = "PDF Files | *.pdf;*.PDF";
            opflDlg.Multiselect = true;
            if (opflDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> selectFiles = opflDlg.FileNames.ToList();
                SaveFileDialog saveDiag = new SaveFileDialog();
                saveDiag.Filter = "PDF Files | *.pdf;*.PDF";
                saveDiag.Title = "保存合并文件";
                if(saveDiag.ShowDialog()== DialogResult.OK)
                {
                    YFASC_PDF.Instance.MergePDF(selectFiles, saveDiag.FileName);
                }
            }
        }

        private void btnRotate_Click(object sender, EventArgs e)
        {
            OpenFileDialog opflDlg = new OpenFileDialog();
            opflDlg.Title = "选择需旋转的pdf文件(可多选)";
            opflDlg.Filter = "PDF Files | *.pdf;*.PDF";
            opflDlg.Multiselect = true;
            if (opflDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> selectFiles = opflDlg.FileNames.ToList();
                selectFiles.ForEach(
                file =>
                {
                    try
                    {
                        YFASC_PDF.Instance.RotatePDFPage(file, 90);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                });
            }
        }

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            OpenFileDialog opflDlg = new OpenFileDialog();
            opflDlg.Title = "选择需加密的pdf文件(可多选)";
            opflDlg.Filter = "PDF Files | *.pdf;*.PDF";
            opflDlg.Multiselect = true;
            if (opflDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> selectFiles = opflDlg.FileNames.ToList();
                PasswordSet SettingDialog = new PDFMergeAndSplitTool.PasswordSet();
                SettingDialog.StartPosition = FormStartPosition.CenterParent;
                if (SettingDialog.ShowDialog() == DialogResult.OK)
                {
                    selectFiles.ForEach(
                    file =>
                    {
                        try
                        {
                            YFASC_PDF.Instance.EncryptPDFFile(file, SettingDialog.Password);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                }
            }
        }

        private void btndecrypt_Click(object sender, EventArgs e)
        {
            OpenFileDialog opflDlg = new OpenFileDialog();
            opflDlg.Title = "选择需消除密码的pdf文件";
            opflDlg.Filter = "PDF Files | *.pdf;*.PDF";
            opflDlg.Multiselect = false;
            if (opflDlg.ShowDialog() == DialogResult.OK)
            {
                List<string> selectFiles = opflDlg.FileNames.ToList();
                PasswordSet SettingDialog = new PDFMergeAndSplitTool.PasswordSet();
                SettingDialog.SetDialogInformation("取消密码", "确定", "文件密码:");
                SettingDialog.StartPosition = FormStartPosition.CenterParent;
                if (SettingDialog.ShowDialog() == DialogResult.OK)
                {
                    selectFiles.ForEach(
                    file =>
                    {
                        try
                        {
                            YFASC_PDF.Instance.CanclePDFPassWord(file, SettingDialog.Password);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    });
                }
            }
        }
    }
}