You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package com.archive.common.convert;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import org.xhtmlrenderer.pdf.ITextFontResolver;
|
|
|
|
|
import org.xhtmlrenderer.pdf.ITextRenderer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class HtmlToPdf
|
|
|
|
|
{
|
|
|
|
|
public static void html2pdf(String htmlFile, String pdfFile) throws Exception {
|
|
|
|
|
String url = (new File(htmlFile)).toURI().toURL().toString();
|
|
|
|
|
System.out.println(url);
|
|
|
|
|
|
|
|
|
|
OutputStream os = new FileOutputStream(pdfFile);
|
|
|
|
|
ITextRenderer renderer = new ITextRenderer();
|
|
|
|
|
renderer.setDocument(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ITextFontResolver fontResolver = renderer.getFontResolver();
|
|
|
|
|
if ("linux".equals(getCurrentOperatingSystem())) {
|
|
|
|
|
fontResolver.addFont("/usr/share/fonts/chiness/simsun.ttc", "Identity-H", true);
|
|
|
|
|
} else {
|
|
|
|
|
fontResolver.addFont("c:/Windows/Fonts/simsun.ttc", "Identity-H", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer.layout();
|
|
|
|
|
renderer.createPDF(os);
|
|
|
|
|
os.close();
|
|
|
|
|
|
|
|
|
|
System.out.println("create pdf done!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getCurrentOperatingSystem() {
|
|
|
|
|
String os = System.getProperty("os.name").toLowerCase();
|
|
|
|
|
System.out.println("---------当前操作系统是-----------" + os);
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Location: C:\Users\Administrator\Desktop\extracted.zip!\extracted\BOOT-INF\classes\com\archive\common\convert\HtmlToPdf.class
|
|
|
|
|
* Java compiler version: 8 (52.0)
|
|
|
|
|
* JD-Core Version: 1.1.3
|
|
|
|
|
*/
|