我可以使用flying-saucer/iText生成PDF。但是,我无法弄清楚如何获取包含在PDF渲染中的样式表。Flying-saucer/iText PDF找不到css文件
我已经使用这个flying-saucer/iText PDF in servlet not finding css file作为参考。
有参与,所以我将无法使用renderer.setDocument(doc, "http://example.com/something/page.html");
作为解决
我已经实现类似于用什么提问者一个东西多个CSS文件,但它返回一个Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 4: http://localhost:8080/proj/resources/css/custom1.css
错误
这里是我的代码
StringBuilder bui = new StringBuilder();
bui.append("<html><head><style>");
bui.append(readFile(path+"/resources/css/custom1.css", Charsets.UTF_8));
bui.append(readFile(path+"/resources/css/custom2.css", Charsets.UTF_8));
bui.append(readFile(path+"/resources/css/custom3.css", Charsets.UTF_8));
bui.append("</style></head>");
bui.append("<body><div><table>");
bui.append(xhtml_file);
bui.append("</table></div></body></html>");
InputStream stream = new ByteArrayInputStream(bui.toString().getBytes(StandardCharsets.UTF_8));
Document doc = tidy.parseDOM(stream, null);
File outputFile = new File(directory+ "FILENAME" +".pdf");
os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
renderer.createPDF(os, false);
renderer.finishPDF();
传递的路径是“http://localhost:8080” 如果我输入“http://localhost:8080/resources/css/custom1.css”直接进入地址BA r,它显示了css文件。我尝试删除'路径',但它也没有得到CSS。我究竟做错了什么?