Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.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 使用外部CSS iTextPdf 7生成PDF文件_Java_Html_Css_Itext_Itext7 - Fatal编程技术网

Java 使用外部CSS iTextPdf 7生成PDF文件

Java 使用外部CSS iTextPdf 7生成PDF文件,java,html,css,itext,itext7,Java,Html,Css,Itext,Itext7,我是iText7新手,正在尝试用外部CSS文件转换HTML页面。守则: @RequestMapping(path = "/pdf/{id}") public ResponseEntity<?> getPDF(@PathVariable Long id, HttpServletRequest request, HttpServletResp

我是iText7新手,正在尝试用外部CSS文件转换HTML页面。守则:

@RequestMapping(path = "/pdf/{id}")
public ResponseEntity<?> getPDF(@PathVariable Long id,
                                HttpServletRequest request,
                                HttpServletResponse response) throws IOException {

    Visit visit = visitService.getById(id);
    List<Service> services = serviceService.getServicesByVisit(visit);

    WebContext context = new WebContext(request, response, servletContext);
    context.setVariable("visitEntity", visit);
    context.setVariable("services", services);
    String orderHtml = templateEngine.process("invoice", context);

    ByteArrayOutputStream target = new ByteArrayOutputStream();
    ConverterProperties converterProperties = new ConverterProperties();
    converterProperties.setBaseUri("http://localhost:8080");

    HtmlConverter.convertToPdf(orderHtml, target, converterProperties);

    byte[] bytes = target.toByteArray();

    return ResponseEntity.ok()
            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=invoice.pdf")
            .contentType(MediaType.APPLICATION_PDF)
            .body(bytes);

}
@RequestMapping(path=“/pdf/{id}”)
公共响应属性getPDF(@PathVariable Long id,
HttpServletRequest请求,
HttpServletResponse(响应)引发IOException{
Visit-Visit=visitService.getById(id);
List services=serviceService.getServicesByVisit(访问);
WebContext上下文=新的WebContext(请求、响应、servletContext);
setVariable(“可视性”,visit);
setVariable(“服务”,服务);
字符串orderHtml=templateEngine.process(“发票”,上下文);
ByteArrayOutputStream目标=新建ByteArrayOutputStream();
ConverterProperties ConverterProperties=新的ConverterProperties();
converterProperties.setBaseUri(“http://localhost:8080");
convertToPdf(orderHtml、target、converterProperties);
byte[]bytes=target.toByteArray();
返回ResponseEntity.ok()
.header(HttpHeaders.CONTENT_处置,“附件;文件名=invoice.pdf”)
.contentType(MediaType.APPLICATION\u PDF)
.正文(字节);
}
PDF文件是使用外部CSS样式正确生成的,但我也遇到一些不会停止应用程序的异常

异常为:java.lang.IllegalArgumentException:不支持 伪css选择器::-moz占位符 java.lang.IllegalArgumentException:不支持的伪css选择器: :-ms输入占位符


提前谢谢你

这些异常是由iText的CSS解析器在遇到它(尚未)支持的伪类或伪元素时生成的。它们只是被记录(如果您配置了记录器),选择器及其声明将被忽略

如果输出正确,则可以忽略这些日志消息(或从CSS输入中删除选择器)

关于您提到的选择器:


这些是特定于供应商的选择器,由
-prefix-
表示:
-moz-
是Mozilla(Firefox)的前缀,
-ms-
是Microsoft(IE和Edge)的前缀。供应商将其用于实验性或非标准CSS功能。iText不太可能支持它们。

一般来说,请在代码块而不是图像中发布代码。这样,如果需要,我们可以轻松复制/粘贴✌️我会记住的,你能用实际代码替换截图吗?在你完成之前,没有人会费心去看你的问题。不是因为他们不想帮忙,相反。但你必须让人们更容易帮助你。