• 图片转换PDF


    组件在我的文件里,需要的可以找找。 




    public partial class MainForm : Form { private string srcFile, destFile; bool success = false; public MainForm() { InitializeComponent(); } private void btnSelectSrc_Click(object sender, EventArgs e) { if (ofdSrcFile.ShowDialog() != DialogResult.OK) return; srcFile = ofdSrcFile.FileName; txbxSrcFile.Text = srcFile; txbxDestFile.Text = Path.GetDirectoryName(srcFile) + "\" + Path.GetFileNameWithoutExtension(srcFile) + ".pdf"; destFile = txbxDestFile.Text; } private void btnSelectDest_Click(object sender, EventArgs e) { if (sfdDestFile.ShowDialog() != DialogResult.OK) return; destFile = sfdDestFile.FileName; txbxDestFile.Text = destFile; } private void btnConvert_Click(object sender, EventArgs e) { errProv.Clear(); if (txbxSrcFile.Text.Length == 0) { errProv.SetError(txbxSrcFile, "Please point source file."); return; } else if (txbxDestFile.Text.Length == 0) { errProv.SetError(txbxDestFile, "Please point destination file."); return; } success = false; bw.RunWorkerAsync(new string[2] { srcFile, destFile }); toolStripProgressBar1.Style = ProgressBarStyle.Marquee; } private void bw_DoWork(object sender, DoWorkEventArgs e) { try { string source = (e.Argument as string[])[0]; string destinaton = (e.Argument as string[])[1]; PdfDocument doc = new PdfDocument(); doc.Pages.Add(new PdfPage()); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]); XImage img = XImage.FromFile(source); xgr.DrawImage(img, 0, 0); doc.Save(destinaton); doc.Close(); success = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { toolStripProgressBar1.Style = ProgressBarStyle.Blocks; toolStripProgressBar1.Value = 0; if (success) MessageBox.Show("The converion ended successfully.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void button1_Click(object sender, EventArgs e) { errProv.Clear(); if (rbSrc.Checked && txbxSrcFile.Text.Length == 0) { errProv.SetError(txbxSrcFile, "Please point source file."); return; } else if (rbDest.Checked && txbxDestFile.Text.Length == 0) { errProv.SetError(txbxDestFile, "Please point destination file."); return; } try { if (rbSrc.Checked) Process.Start(srcFile); else if (rbDest.Checked) Process.Start(destFile); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
  • 相关阅读:
    MySQL binlog 组提交与 XA(分布式事务、两阶段提交)【转】
    一致性哈希算法原理
    【MySQL (六) | 详细分析MySQL事务日志redo log】
    Replication基础(六) 复制中的三个线程(IO/SQL/Dump)
    硬盘基本知识(磁头、磁道、扇区、柱面
    MySQL架构总览->查询执行流程->SQL解析顺序
    Redis之AOF重写及其实现原理
    MySQL binlog中的事件类型
    linux(mac) 编译安装MySQL
    写给自己看的Linux运维基础(四)
  • 原文地址:https://www.cnblogs.com/qigao/p/5992027.html
Copyright © 2020-2023  润新知