12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using Aspose.Note;
- using Aspose.Note.Saving;
- using OneNote2PDF.Utils;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OneNote2PDF
- {
- public partial class MainForm : Form
- {
- App app;
- public MainForm()
- {
- InitializeComponent();
- }
- private void btnConvert_Click(object sender, EventArgs e)
- {
- // 判断输入 OneNote 笔记目录是否正确
- if (app.inputDir!=null || app.inputDir!="")
- {
- lbConvertResult.Text = "正在转换中,请稍耐心等待...";
- foreach (DirectoryInfo subDirInfo in (new DirectoryInfo(app.inputDir)).GetDirectories())
- {
- string subDir = Path.Combine(app.outputDir, subDirInfo.Name); //输出目录
- if (!Directory.Exists(subDir))
- {
- Directory.CreateDirectory(subDir);
- }
- foreach (FileInfo file in subDirInfo.GetFiles())
- {
- //只有后缀为one的文件才处理
- if (file.Name.Substring(file.Name.Length - 3, 3) == "one")
- {
- // 异步执行
- ThreadStart starter = delegate {
- OneNoteUtils.One2PDF(file.FullName, Path.Combine(app.outputDir, subDirInfo.Name, file.Name.Substring(0, file.Name.Length - 4) + ".pdf"));
- };
- new Thread(starter).Start();
- }
- return;
- }
- lbConvertResult.Text = "全部转换成功";
- }
- }
- else
- {
- MessageBox.Show("请先选择正确的 OneNote 笔记目录再执行转换。");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- folderBrowserDialog1.Description = "请选择文件夹";
- if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (string.IsNullOrEmpty(folderBrowserDialog1.SelectedPath))
- {
- MessageBox.Show(this, "文件夹路径不能为空", "提示");
- return;
- }
- else
- {
- app.inputDir = folderBrowserDialog1.SelectedPath;
- tbInputDir.Text = app.inputDir;
- }
- }
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- app = App.getInstance();//初始化app对象
- tbOutputDir.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),"Output");
- app.outputDir = tbOutputDir.Text;
- }
- }
- }
|