package org.fouram.core.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class TesseractUtil {

	/**
	 * tesseract.exe -l chi_sim 001.jpg 001 pdf
	 */
	public static boolean toPDF(String inputImageFile, String outPdfFile) {
		if (new File(outPdfFile + ".pdf").exists()) {
			return true;
		}
		List<String> commend = new ArrayList<String>();
		commend.add(ConfConfig.getConfigString("tesseract.path"));
		commend.add("-l");
		commend.add("chi_sim");
		commend.add(inputImageFile);
		commend.add(outPdfFile);
		commend.add("pdf");
		try {
			ProcessBuilder builder = new ProcessBuilder();
			builder.command(commend);
			Process p = builder.start();
			p.waitFor();
			if (new File(outPdfFile).exists()) {
				return true;
			}else{
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static void main(String[] args) {
		TesseractUtil.toPDF("D:\\001.jpg", "D:\\001");
	}
} 