• 图片转换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); } } }
  • 相关阅读:
    spark-submit python egg 解决三方件依赖问题
    怎样制作一个 Python Egg
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(4月23日)
    2016最新住房贷款利率,首套房利率,二套房利率,公积金贷款利率--利率表
    xgboost: 速度快效果好的boosting模型
    苏州Uber优步司机奖励政策(4月22日)
    北京Uber优步司机奖励政策(4月22日)
    成都Uber优步司机奖励政策(4月22日)
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(4月22日)
    苏州Uber优步司机奖励政策(4月21日)
  • 原文地址:https://www.cnblogs.com/qigao/p/5992027.html
Copyright © 2020-2023  润新知