嗨,这是我的代码从html源生成pdf,html得到了完美但有些是pdf错过了那个字体和文本
try{
StringBuffer buf = new StringBuffer("");
buf.append("<html><head><style>@font-face {font-family:gautami;src:url(C:\\Documents and Settings\\Administrator\\Desktop\\font\\gautami.ttf);-fs-pdf-font-embed: embed;-fs-pdf-font-encoding: Identity-H;} .col{color:red;}</style></head><body style='font-family:gautami'>");
//List<File> fil = fileGallaryDAO.getNews();
// for (File movie : fil) {
// create the snippet
buf.append("<div class='col'> రాష్ట్ర విభజన కోసం రాజ్యాంగ సవరణ</div>");
// use the snippet for the HTML page
// }
buf.append("<div class='col'>fgfdhd</div></body></html>");
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont (
"C:\\Documents and Settings\\Administrator\\Desktop\\font\\gautami.ttf",
"UTF-8",
BaseFont.EMBEDDED
);
PrintStream out = new PrintStream(new FileOutputStream("C:\\Documents and Settings\\Administrator\\Desktop\\htmlpdf\\new.html"));
out.println(buf.toString());
out.flush();
out.close();
//renderer.setDocument(buf.toString());
renderer.setDocument(new java.io.File("C:\\Documents and Settings\\Administrator\\Desktop\\htmlpdf\\new.html"));
String outputFile = "C:\\Documents and Settings\\Administrator\\Desktop\\htmlpdf\\newpdf.pdf";
OutputStream os = new FileOutputStream(outputFile);
renderer.layout();
renderer.createPDF(os);
os.flush();
os.close();
}catch(Exception e){
e.printStackTrace();
}
}
html文件输出:
రాష్ట్ర విభజన కోసం రాజ్యాంగ సవరణ
fgfdhd
pdf文件输出:
fgfdhd
甚至字体都没有嵌入pdf中,错过了文字?