private void convert() { converter = ImageConverterFactory.CreateImageConverter(_extension); converter.OnConvertFailed += converter_OnConvertFailed; converter.OnConvertSucceed += converter_OnConvertSucceed; converter.OnProgressChanged += converter_OnProgressChanged; converter.ConvertToImage(_file_path, _save_path, _start_page, _end_page); }
private void btn_filepath_Click(object sender, EventArgs e) { try { OpenFileDialog fdlg = new OpenFileDialog(); fdlg.Title = "请选择需要转换的文件(PDF,Word或Excel)"; fdlg.InitialDirectory = @"c:\"; //@是取消转义字符的意思 fdlg.Filter = "文档文件|*.doc;*.docx;*.xls;*.xlsx;*.pdf"; /* * FilterIndex 属性用于选择了何种文件类型,缺省设置为0,系统取Filter属性设置第一项 * ,相当于FilterIndex 属性设置为1.如果你编了3个文件类型,当FilterIndex =2时是指第2个. */ fdlg.FilterIndex = 0; /* *如果值为false,那么下一次选择文件的初始目录是上一次你选择的那个目录, *不固定;如果值为true,每次打开这个对话框初始目录不随你的选择而改变,是固定的 */ fdlg.RestoreDirectory = true; if (fdlg.ShowDialog() == DialogResult.OK) { var extension = System.IO.Path.GetExtension(fdlg.FileName); if (!ImageConverterFactory.Support(extension)) { MessageBox.Show("转换器不支持该类型文件"); return; } _extension = extension; _file_path = fdlg.FileName; txt_filepath.Text = fdlg.FileName; var arr = System.IO.Path.GetFileNameWithoutExtension(fdlg.FileName).Split('/').ToArray(); _file_name = arr[0]; _save_path = fdlg.FileName.Substring(0, fdlg.FileName.LastIndexOf(".")) + "\\"; txt_savepath.Text = _save_path; } } catch (Exception ex) { MessageBox.Show("内部出错"); } }