Пример #1
0
        public DemoTemplateForm()
        {
            InitializeComponent();

            btnAdd.Click            += btnAdd_Click;
            btnUpdateTemplate.Click += btnUpdateTemplate_Click;
            pbPreview.MouseUp       += OnMouseUp;
            pbPreview.MouseDown     += pbPreview_MouseDown;
            pbPreview.MouseMove     += pbPreview_MouseMove;
            pbPreview.Paint         += pbPreview_Paint;

            lstLoadedImages.SelectedIndexChanged += lstLoadedImages_SelectedIndexChanged;
            dataGridView1.RowHeaderMouseClick    += dataGridView1_RowHeaderMouseClick;
            dataGridView2.CellContentClick       += dataGridView2_CellContentClick;
            dataGridView2.RowHeaderMouseClick    += dataGridView2_RowHeaderMouseClick;
            //Add Columns
            AddItemListView();
            //  dataGridView();

            btnChooseFile.Click += btnChooseFile_Click;


            this.WindowState = FormWindowState.Maximized;

            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox     = false;
            this.StartPosition   = FormStartPosition.CenterScreen;

            int h = Screen.PrimaryScreen.WorkingArea.Height;
            int w = Screen.PrimaryScreen.WorkingArea.Width;

            this.Height      = h;
            this.Width       = w;
            panel3.Height    = h;
            panel1.Height    = h;
            panel2.Height    = h;
            panel3.Width     = w - (panel1.Width + panel2.Width);
            pbPreview.Width  = panel3.Width;
            pbPreview.Height = h;

            //pbPreview.Height = h;

            m_bCancelRequested   = false;
            m_bActiveRecognition = false;
            m_UpdateProgress     = new UpdateProgressDelegate(UpdateProgressSafe);
            m_nSelectedPageIndex = -1;

            // Lấy số page hiện tại
            m_Page = SmartOcrSdkExports.OCR_GetPageCount();
            if (!string.IsNullOrEmpty(FileTemplateOCR_DTO.m_Path))
            {
                AddFromPageOrc(FileTemplateOCR_DTO.m_Path);
                FileTemplateOCR_DTO.m_Path = string.Empty;
            }
        }
Пример #2
0
        public void AddFromPageOrc(string m_FileName)
        {
            string ext = Path.GetExtension(m_FileName);

            m_strPath = m_FileName;
            int pageSelectIndex = 0;

            m_PageOld = SmartOcrSdkExports.OCR_GetPageCount();
            if (m_PageOld > m_Page)
            {
                for (int i = m_Page; i < m_PageOld; i++)
                {
                    var nPageIndex = m_Page;
                    SmartOcrSdkExports.OCR_RemovePage(nPageIndex);
                }
                lstLoadedImages.Items.Clear();
            }
            if (ext == ".pdf")
            {
                SmartOcrSdkExports.OCR_AddPagesFromPDF(m_FileName, null, IntPtr.Zero);
            }
            else
            {
                SmartOcrSdkExports.OCR_AddPageFromImage(m_FileName);
            }
            int nPageCount = SmartOcrSdkExports.OCR_GetPageCount() - m_Page;
            int index      = lstLoadedImages.Items.Count;

            if (nPageCount > 1)
            {
                for (int i = 0; i < nPageCount; i++)
                {
                    pageSelectIndex++;
                    string filePath = "";
                    filePath = m_FileName + "_page" + pageSelectIndex;
                    lstLoadedImages.Items.Add(filePath);
                }
            }
            else
            {
                lstLoadedImages.Items.Add(m_FileName);
            }
            // Automatically select the first item
            if (lstLoadedImages.SelectedItem == null)
            {
                lstLoadedImages.SelectedIndex = 0;
            }
        }
Пример #3
0
 private void TemplateForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         // Release the OCR engine
         int nPageCount = SmartOcrSdkExports.OCR_GetPageCount();// -m_PageOld;
         for (int i = m_Page; i < nPageCount; i++)
         {
             var nPageIndex = m_Page;
             int res        = SmartOcrSdkExports.OCR_RemovePage(nPageIndex);
         }
     }
     catch (System.Exception)
     {
     }
 }