Beispiel #1
0
        /// <summary>
        /// 开始转换
        /// </summary>
        public void StartConvert(object p)
        {
            var savePath   = _mainForm.LbllblSavePath.Text;
            var parameters = p as List <object>;

            _convertingtablerowIndex = Convert.ToInt32(parameters[0]);
            var             noticeAction          = parameters[1];
            var             convertCompleteAction = parameters[2];
            ConvertComplete completedCalback      = convertCompleteAction as ConvertComplete;
            ProgressNotice  noticeCallback        = noticeAction as ProgressNotice;
            var             imgType = parameters[3].ToString();

            foreach (Row row in this.tableFiles.TableModel.Rows)
            {
                var filePath     = row.Cells[FilePathColIndex].Text;
                var fileName     = row.Cells[FileNameColIndex].Text;
                var fullFileName = Path.Combine(savePath, fileName.Contains(".") ?
                                                fileName.Remove(fileName.LastIndexOf(".")) : fileName);
                if (!Directory.Exists(fullFileName))
                {
                    Directory.CreateDirectory(fullFileName);
                }

                try
                {
                    row.Tag = ConvertState.Converting;
                    HandleDocumentToImg(filePath, fullFileName, imgType, noticeCallback, _convertingtablerowIndex);
                }
                catch (Exception ex)
                {
                    row.Tag = ConvertState.NotConvert;
                    if (ex is InvalidPasswordException)
                    {
                        var noticeResult = new NoticeResult
                        {
                            Success = false,
                            ErrMsg  = $"文件\n{fileName}\n是加密文件,请先解密!"
                        };
                        this.Invoke(noticeCallback, noticeResult);
                    }
                    else
                    {
                        throw;
                    }
                }
                //标志为转换完成
                if ((ConvertState)row.Tag == ConvertState.Converting)
                {
                    row.Tag = ConvertState.Converted;
                }
                _convertingtablerowIndex++;
            }
            this.Invoke(completedCalback);
            convertThread = null;
        }
Beispiel #2
0
        private void btnStartConvert_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_mainForm.LbllblSavePath.Text.Trim()))
            {
                YMessageBox.ShowMsgBox(100, "请先选择要保存的路径!");
                return;
            }

            this.btnStartConvert.Text = "转换中...";
            SetConvertBtnEnable(false);
            ProgressNotice  notice           = ProgressAction;//创建一个委托对象
            ConvertComplete convertCompleted = ConvertCompleteAction;

            if (convertThread != null)
            {
                convertThread = null;
            }
            convertThread = new Thread(StartConvert);
            var imgType = GetConvertedImgType();

            convertThread.Start(new List <object> {
                0, notice, convertCompleted, imgType
            });
        }
Beispiel #3
0
 private void TableFiles_CellMouseDown(object sender, XPTable.Events.CellMouseEventArgs e)
 {
     if (e.Column == DeleteColIndex)
     {
         var currentRow = this.tableFiles.TableModel.Rows[e.Row];
         this.tableFiles.TableModel.Rows.RemoveAt(e.Row);
         if (this.tableFiles.TableModel.Rows.Count <= 0)
         {
             if (convertThread != null && convertThread.IsAlive)
             {
                 convertThread.Abort();
             }
             SetConvertBtnVisiable(false);
             ConvertCompleteAction();
             AddDragTip();
             return;
         }
         //判断移除行转换的状态
         //重启线程转换
         ProgressNotice  notice           = ProgressAction;//创建一个委托对象
         ConvertComplete convertCompleted = ConvertCompleteAction;
         if (convertThread != null && convertThread.IsAlive)
         {
             convertThread.Abort();
         }
         convertThread = new Thread(StartConvert);
         var imgType = GetConvertedImgType();
         if ((ConvertState)currentRow.Tag == ConvertState.Converted)
         {
             _convertingtablerowIndex--;
         }
         convertThread.Start(new List <object> {
             _convertingtablerowIndex, notice, convertCompleted, imgType
         });
     }
 }
Beispiel #4
0
        private void HandleDocumentToImg(string filePath, string fullFileName, string imgType, ProgressNotice noticeCallback, int rowIndex)
        {
            Document pdfDocument = new Document(filePath);
            var      pageCount   = pdfDocument.Pages.Count;
            var      realPercent = 0.0;

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                realPercent += (double)100 / pageCount;
                using (FileStream imageStream = new FileStream(fullFileName + "\\" + pageIndex + imgType,
                                                               FileMode.Create))
                {
                    Resolution resolution = new Resolution(300);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                    jpegDevice.Process(pdfDocument.Pages[pageIndex], imageStream);
                    imageStream.Close();
                }
                if (pageIndex == pdfDocument.Pages.Count)
                {
                    realPercent = 100;
                }
                var noticeResult = new NoticeResult
                {
                    Success   = true,
                    rowIndex  = rowIndex,
                    pageIndex = pageIndex,
                    per       = (int)realPercent
                };
                this.Invoke(noticeCallback, noticeResult);
            }
        }