pdf2htmlEX to convert pdf to html to generate page by executing command in java

Keywords: Programming Java

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

  1. 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
            StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(), "STDOUT");
            // kick off stdout
            int w = p.waitFor();
            int v = p.exitValue();
            return true;
        } catch (Exception e) {
        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",
        };// cmd is the dos command to execute


Posted by cluce on Sun, 10 Nov 2019 06:46:59 -0800