使用pdfdom将pdf转为html

pdfbox自带的转换html的方法效果不是太好,pdfdom是基于pdfbox的,在此之上加强了转换html的能力。

maven

        
            net.sf.cssbox
            pdf2dom
            1.6
        

        
            org.apache.pdfbox
            pdfbox
            2.0.4
        

        
            org.apache.pdfbox
            pdfbox-tools
            2.0.4
        

使用

public void generateHTMLFromPDF(String filename) throws IOException, ParserConfigurationException {
        PDDocument pdf = PDDocument.load(new File(filename));
        Writer output = new PrintWriter("pdf.html", "utf-8");
        new PDFDomTree().writeText(pdf, output);
        output.close();
}

或者

public void convertPdf2Html(File input,Writer out) throws IOException, ParserConfigurationException {
        PDDocument pdf = PDDocument.load(input);
        PDFDomTree tree = new PDFDomTree();
        tree.writeText(pdf,out);
}

doc

  • Pdf2Dom

你可能感兴趣的:(pdf)