zoukankan      html  css  js  c++  java
  • 图片转换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); } } }
  • 相关阅读:
    android 选择图片 剪裁 拍照 兼容所有版本的代码
    bitmap_createScaledBitmap的方法
    ViewPager的滑动监听事件
    android效果背景虚化
    Python socket超时
    Python 半开放socket
    Python绑定方法,未绑定方法,类方法,实例方法,静态方法
    Python类属性,实例属性
    Python偏函数
    Python filter,map,lambda,reduce,列表解析
  • 原文地址:https://www.cnblogs.com/qigao/p/5992027.html
Copyright © 2011-2022 走看看