package ocrsample; import java.awt.BorderLayout; import java.awt.Rectangle; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import com.qoppa.ocr.OCRBridge; import com.qoppa.pdfEditor.PDFEditorBean; public class OCRSample extends JFrame { private JPanel jPanel = null; private PDFEditorBean pdfEditorBean = null; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final OCRSample sf = new OCRSample(); sf.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { try { // Path to directory with native libraries String libDir = "/temp/libtess"; // Path to directory with language data files // NOTE: The data folder needs to be called "tessdata" String langDir = "/temp/tessdata"; // Initialize the OCR bridge OCRBridge.initialize(libDir, langDir); if (OCRBridge.isLoaded()) { // Activate the OCR function sf.getPDFEditorBean().activateOCR(); } } catch (Throwable t) { t.printStackTrace(); sf.getPDFEditorBean().showError("Unable to load OCRBridge", t); } } }); sf.setVisible(true); } }); } /** * This method initializes * */ public OCRSample() { super(); initialize(); } /** * This method initializes this * */ private void initialize() { this.setBounds(new Rectangle(0, 0, 1080, 600)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setContentPane(getJPanel()); this.setTitle("Qoppa Software - jPDFEditor OCR Sample"); this.setLocationRelativeTo(null); } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(new BorderLayout()); jPanel.add(getPDFEditorBean(), BorderLayout.CENTER); } return jPanel; } /** * This method initializes PDFViewerBean * * @return com.qoppa.pdfViewer.PDFViewerBean */ private PDFEditorBean getPDFEditorBean() { if (pdfEditorBean == null) { pdfEditorBean = new PDFEditorBean(); } return pdfEditorBean; } }