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; } }
void btnChooseFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { string ext = Path.GetExtension(openFileDialog.FileName); string fileName = openFileDialog.FileName; int pageSelectIndex = 0; int nPageCount_1 = SmartOcrSdkExports.OCR_GetPageCount(); if (ext == ".pdf") { SmartOcrSdkExports.OCR_AddPagesFromPDF(fileName, null, IntPtr.Zero); } else { SmartOcrSdkExports.OCR_AddPageFromImage(fileName); } int nPageCount = SmartOcrSdkExports.OCR_GetPageCount() - nPageCount_1; int index = lstLoadedImages.Items.Count; if (nPageCount > 1) { for (int i = 0; i < nPageCount; i++) { pageSelectIndex++; string filePath = ""; filePath = fileName + "_page" + pageSelectIndex; lstLoadedImages.Items.Add(filePath); } } else { lstLoadedImages.Items.Add(fileName); } // Automatically select the first item if (lstLoadedImages.SelectedItem == null) { lstLoadedImages.SelectedIndex = 0; } else { lstLoadedImages.SelectedIndex = lstLoadedImages.Items.Count - nPageCount; } } }