亲测代码没有问题,需要注意细节已经标注;需要jar包:iText-2.0.8.jar;core-renderer-R8.jar;
import com.lowagie.text.pdf.BaseFont;
import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class HtmlToPDF {
public static void main(String[] args) throws Exception {
htmlToPdf("C://Users//Administrator//Desktop//20181001.pdf","C://Users//Administrator//Desktop//xse//newFile.html");
}
/**
* 把URL转换为PDF
* @param outputFile
* , 示例:/data/fs/inspector/BJ20150522001.pdf
* @param url
* ,示例:http :xxxx
* @return
* @throws Exception
*/
public static void htmlToPdf(String outputFile, String url)throws Exception {
try{
OutputStream os = new FileOutputStream(