Java 使用itext和飞碟将html转换为pdf时未嵌入字体
您好,这是我从html源代码生成pdf的代码,html得到了完美的效果,但pdf遗漏了一些字体和文本Java 使用itext和飞碟将html转换为pdf时未嵌入字体,java,flying-saucer,Java,Flying Saucer,您好,这是我从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\\Deskt
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();
}
}
pdf文件输出:
fgfdhd
甚至pdf中也没有嵌入字体,文本也丢失了?您可以确保doctype设置正确。您是如何解决这个问题的?
fgfdhd