Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用itext和飞碟将html转换为pdf时未嵌入字体_Java_Flying Saucer - Fatal编程技术网

Java 使用itext和飞碟将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

您好,这是我从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'> &#3120;&#3134;&#3127;&#3149;&#3103;&#3149;&#3120; &#3125;&#3135;&#3117;&#3100;&#3112; &#3093;&#3147;&#3128;&#3074; &#3120;&#3134;&#3100;&#3149;&#3119;&#3134;&#3074;&#3095; &#3128;&#3125;&#3120;&#3107;</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