62,614
社区成员
发帖
与我相关
我的任务
分享
import java.io.File;
import java.io.FileOutputStream;
import java.io.StringReader;
import org.zefer.pd4ml.PD4Constants;
import org.zefer.pd4ml.PD4ML;
public class Converter {
public static void main(String[] args) throws Exception {
Converter converter = new Converter();
converter.generatePDF_2(new File("D:/Test/demo_ch_pd4ml_a.pdf"), "D:/Test/a.htm");
}
// HTML代码来自于HTML文件
public void generatePDF_2(File outputPDFFile, String inputHTMLFileName) throws Exception {
FileOutputStream fos = new FileOutputStream(outputPDFFile);
PD4ML pd4ml = new PD4ML();
//pd4ml.setPageInsets(new Insets(30, 30, 30, 30));
//pd4ml.setHtmlWidth(800);
//pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
pd4ml.setPageSize(PD4Constants.A4);
pd4ml.useTTF("java:fonts", true);
pd4ml.setDefaultTTFs("MSJH", "Arial", "Courier New");
pd4ml.enableDebugInfo();
pd4ml.render("file:" + inputHTMLFileName, fos);
}
}
KaiTi_GB2312=SIMFANG.TTF
<style type="text/css">
*{
font-family:KaiTi_GB2312;
}
</style>