java完成PDF转HTMLITeyefenghuang - 乐橙lc8

java完成PDF转HTMLITeyefenghuang

2018-10-07 10:58:22 | 作者: 问凝 | 标签: 文件,途径,空格 | 浏览: 2775

package org.common.util.pdftohtml;
import org.common.util.pdftohtml.StreamGobbler;
 * @author liuzhengyong
 * @version 1.0 时刻:2013-12-30 下午2:24:10 pdf文件转html东西类
public class Pdf2htmlEXUtil {
 * 调用pdf2htmlEX将pdf文件转换为html文件
 * @param exeFilePath
 * pdf2htmlEX.exe文件途径
 * @param pdfFile
 * pdf文件绝对途径
 * @param [destDir] 生成的html文件寄存途径
 * @param htmlName
 * 生成的html文件名称
 * @return
 public static boolean pdf2html(String exeFilePath, String pdfFile,
 String destDir, String htmlFileName) {
 if (!(exeFilePath != null !"".equals(exeFilePath) pdfFile != null
 !"".equals(pdfFile) htmlFileName != null !""
 .equals(htmlFileName))) {
 System.out.println("传递的参数有误!");
 return false;
 Runtime rt = Runtime.getRuntime();
 StringBuilder command = new StringBuilder();
 command.append(exeFilePath).append(" ");
 if (destDir != null !"".equals(destDir.trim()))// 生成文件寄存方位,需求替换文件途径中的空格
 command.append("dest-dir ").append(destDir.replace(" ", "\" \""))
 .append(" ");
 command.append("optimize-text 1 ");// 尽量削减用于文本的HTML元素的数目 (default: 0)
 command.append("zoom 1.4 ");
 command.append("process-outline 0 ");// html中显现链接:0——false,1——true
 command.append("font-format woff ");// 嵌入html中的字体后缀(default ttf)
 // ttf,otf,woff,svg
 command.append(pdfFile.replace(" ", "\" \"")).append(" ");// 需求替换文件途径中的空格
 if (htmlFileName != null !"".equals(htmlFileName.trim())) {
 command.append(htmlFileName);
 if (htmlFileName.indexOf(".html")  -1)
 command.append(".html");
 try {
 System.out.println("Command:" + command.toString());
 Process p = rt.exec(command.toString());
 StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(),
 "ERROR");
 // 敞开屏幕规范过错流
 errorGobbler.start();
 StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(),
 "STDOUT");
 // 敞开屏幕规范输出流
 outGobbler.start();
 int w = p.waitFor();
 int v = p.exitValue();
 if (w  0 v  0) {
 return true;
 } catch (Exception e) {
 e.printStackTrace();
 return false;
 public static boolean pdf2html_linux(String pdfFile, String destDir,
 String htmlFileName) {
 if (!(pdfFile != null !"".equals(pdfFile) htmlFileName != null !""
 .equals(htmlFileName))) {
 System.out.println("传递的参数有误!");
 return false;
 Runtime rt = Runtime.getRuntime();
 StringBuilder command = new StringBuilder();
 command.append("pdf2htmlEX").append(" ");
 if (destDir != null !"".equals(destDir.trim()))// 生成文件寄存方位,需求替换文件途径中的空格
 command.append("dest-dir ").append(destDir.replace(" ", "\" \""))
 .append(" ");
 command.append("optimize-text 1 ");// 尽量削减用于文本的HTML元素的数目 (default: 0)
 command.append("process-outline 0 ");// html中显现链接:0——false,1——true
 command.append("font-format woff ");// 嵌入html中的字体后缀(default ttf)
 // ttf,otf,woff,svg
 command.append(pdfFile.replace(" ", "\" \"")).append(" ");// 需求替换文件途径中的空格
 if (htmlFileName != null !"".equals(htmlFileName.trim())) {
 command.append(htmlFileName);
 if (htmlFileName.indexOf(".html")  -1)
 command.append(".html");
 try {
 System.out.println("Command:" + command.toString());
 Process p = rt.exec(command.toString());
 StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(),
 "ERROR");
 // 敞开屏幕规范过错流
 errorGobbler.start();
 StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(),
 "STDOUT");
 // 敞开屏幕规范输出流
 outGobbler.start();
 int w = p.waitFor();
 int v = p.exitValue();
 if (w  0 v  0) {
 return true;
 } catch (Exception e) {
 e.printStackTrace();
 return false;
 public static void main(String[] args) {
 pdf2html("D:\\pdf2htmlEX-v1.0\\pdf2htmlEX.exe","D:\\pdf2htmlEX-v1.0\\PDF\\my.pdf","D:\\pdf2htmlEX-v1.0\\HTML","my.html");
}
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表乐橙lc8立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章