Word,PPT,Word,execl转PDF 
  
 
excel原文如下: 转换后pdf如下:
 转换后pdf如下: 
 
using GxNetExtend;using System;using System.IO;using System.Threading.Tasks;using System.Windows.Forms;namespace ConvertPDF{  public partial class Form1 : Form  {    public string path;    public string trapath;    public Form1()    {      InitializeComponent();    }    private void button1_Click(object sender, EventArgs e)    {      OpenFileDialog dialog = new OpenFileDialog();      dialog.Multiselect = false;//该值确定是否可以选择多个文件      dialog.Title = "请选择文件夹";      dialog.Filter = "所有文件(*.*)|*.*";      if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)      {        string file = dialog.FileName;        //MessageBox.Show(file);        // label1.Text = file;        path = file;      }    }    private void label1_Click(object sender, EventArgs e)    {    }    private async void button2_Click(object sender, EventArgs e)    {      System.DateTime currentTime = new System.DateTime();      // 取当前年月日时分秒      currentTime = System.DateTime.Now;      //取当前年      int 年 = currentTime.Year;      //取当前月        int 月 = currentTime.Month;      // 取当前日       int 日 = currentTime.Day;      //取当前时        int 时 = currentTime.Hour;      // 取当前分       int 分 = currentTime.Minute;      //取当前秒        int 秒 = currentTime.Second;      // 取当前毫秒        int 毫秒 = currentTime.Millisecond;      string 时间 = 年.ToString()  月.ToString()  日.ToString()  时.ToString()  分.ToString()  秒.ToString()  毫秒.ToString();      FileStream fs = new FileStream(trapath  时间 .Trim() ".PDF", FileMode.CreateNew);      StreamWriter sw = new StreamWriter(fs);      // sw.Write("你好啊"); //这里是写入的内容      sw.Close();      PdfUtil getPdfUtil = new PdfUtil();      label1.Text = "正在转换....";      bool a = await Task.Run<bool>(() => getPdfUtil.convert2PDF(path, trapath  时间.Trim()  ".PDF"));      label1.Text = "转换成功!";    }    private async void label2_Click(object sender, EventArgs e)    {        System.DateTime currentTime = new System.DateTime();      // 取当前年月日时分秒      currentTime = System.DateTime.Now;      //取当前年      int 年 = currentTime.Year;      //取当前月        int 月 = currentTime.Month;      // 取当前日       int 日 = currentTime.Day;      //取当前时        int 时 = currentTime.Hour;      // 取当前分       int 分 = currentTime.Minute;      //取当前秒        int 秒 = currentTime.Second;      // 取当前毫秒        int 毫秒 = currentTime.Millisecond;      string 时间 = 年.ToString()  月.ToString()  日.ToString()  时.ToString()  分.ToString()  秒.ToString()  毫秒.ToString();      FileStream fs = new FileStream(trapath  textBox1.Text.Trim()  ".PDF", FileMode.CreateNew);      StreamWriter sw = new StreamWriter(fs);      // sw.Write("你好啊"); //这里是写入的内容      sw.Close();      PdfUtil getPdfUtil = new PdfUtil();      label1.Text = "正在转换....";      bool a = await Task.Run<bool>(() => getPdfUtil.convert2PDF(path, trapath  textBox1.Text.Trim()  ".PDF"));      label1.Text = "转换成功!";    }    private void button3_Click(object sender, EventArgs e)    {      System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();      dialog.Description = "请选择Txt所在文件夹";      if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)      {        if (string.IsNullOrEmpty(dialog.SelectedPath))        {          MessageBox.Show(this, "文件夹路径不能为空", "提示");        }        else        {          trapath = dialog.SelectedPath.ToString() @"\";          // MessageBox.Show(this, dialog.SelectedPath.ToString(), "提示");        }              }    }    }}

 
  
					
				
评论