环境:itextpdf-5.5.5.jar xmlworker-5.5.5.jar
尝试做个csdn博文下载器,首要解决的任务是html转pdf,百度到IText,查了很多教程Itext版本都比较老,我下的5.5.5的。
代码不复杂,
public static void main(String[] args) throws FileNotFoundException,
Exception {
String htmlFile = "C:\\Users\\Administrator\\Desktop\\test.htm";
String pdfFile = "C:\\Users\\Administrator\\Desktop\\test.pdf";
// PdfUtils.parseHTML2PDFFile(pdfFile, new FileInputStream(htmlFile));
String ss = "";
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(htmlFile), "UTF-8"));
String t = "";
while ((t = br.readLine()) != null) {
// System.out.println(t);
ss += t;
}
PdfUtils.parseHTML2PDFFile2(pdfFile, ss);
}
public static void parseHTML2PDFFile2(String pdfFile, String html)
throws DocumentException, IOException {