Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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
Html 使用飞碟生成PDF时加载图像_Html_Css_Pdf_Flying Saucer - Fatal编程技术网

Html 使用飞碟生成PDF时加载图像

Html 使用飞碟生成PDF时加载图像,html,css,pdf,flying-saucer,Html,Css,Pdf,Flying Saucer,我使用下面的代码来生成PDF使用CSS现在我使用内联CSS,因为我不能从外部加载CSS File file = new File(path + "\\" + id + "\\" + fileName + ".pdf"); ServletOutputStream outputStream = response.getOutputStream(); FileOutputStream fos = new Fil

我使用下面的代码来生成PDF使用CSS现在我使用内联CSS,因为我不能从外部加载CSS

File file = new File(path + "\\" + id + "\\" + fileName + ".pdf");
        ServletOutputStream outputStream = response.getOutputStream();
        FileOutputStream fos = new FileOutputStream(file);
        ITextRenderer renderer = new ITextRenderer();
        StringBuilder htmls = new StringBuilder();
        htmls.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        htmls.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
        htmls.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
        /*htmls.append("<head><style type=\"text/css\">");
        htmls.append("body{text-decoration: none; font-family: Arial, Verdana,Helvetica,sans-serif; font-size:12px;}");
        htmls.append("</style></head>");*/
        htmls.append("<head><style type=\"text/css\">");
        htmls.append(".gradi{background:url(resources/template/template1/images/grad.jpg) repeat-x!important}");
        htmls.append("</style></head>");
        htmls.append("<body>html body</body></html>");
        renderer.setDocumentFromString(htmls.toString());
            renderer.layout();
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + ".pdf\"");
            renderer.createPDF(outputStream);
            renderer.createPDF(fos);
htmls.append(".gradi{background:url(resources/template/template1/images/grad.jpg) repeat-x!important}");