Through Java code, when using pdf2htmlEX plug-in to generate html page, a problem is found. Only execute cmd command can generate html page, but java code can't execute.
As for how to implement the code and what you need to download, you can see this. I won't repeat that https://blog.csdn.net/crazypandariy/article/details/17663731#
But in the above link, execute the cmd command with the main function to find the error
public static void main(String[] args) { pdf2html("D:\\pdf2htmlEX-v1.0\\pdf2htmlEX.exe D:\\v.pdf hello.html","v.pdf","v2.html"); }
, I wonder if there is a problem with the plug-in, so I searched the Internet and found that it can be realized through the following methods
- Execute the cmd command to call pdf2htmlex for conversion:
pdf2htmlex --zoom 1.8 v.pdf
So I changed the java code myself.
public class Pdf2htmlEXUtil { /** * Call pdf2htmlEX to convert PDF file to html file * @param command Is the dos command to execute * @param dir Here is the directory specified by pdf2htmlEX.exe * @return */ public static boolean pdf2html(String[] command,File dir){ Runtime rt = Runtime.getRuntime(); try { Process p = rt.exec(command,null,dir); StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR"); // kick off stderr errorGobbler.start(); StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(), "STDOUT"); // kick off stdout outGobbler.start(); int w = p.waitFor(); System.out.println(w); int v = p.exitValue(); System.out.println(v); return true; } catch (Exception e) { e.printStackTrace(); } return false; } public static void main(String[] args) { File dir = new File("D:\\IdeaProjects\\pdf2htmlexe");Here is pdf2htmlEX.exe Specified directory String commond="pdf2htmlex --zoom 1.8 D:\\IdeaProjects\\pdf2htmlexe\\pdf\\v.pdf"; String[] cmd = new String[] { "cmd", "/c", commond };// cmd is the dos command to execute pdf2html(cmd,dir); }