Reputation: 41
I am new to iText 7 and trying to convert HTML page with external CSS file. The code:
@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);
}
The PDF file is generated correctly with the external CSS style, but I also get some exceptions that do not stop the application.
The exceptions are: java.lang.IllegalArgumentException: Unsupported pseudo css selector: :-moz-placeholder and java.lang.IllegalArgumentException: Unsupported pseudo css selector: :-ms-input-placeholder
Thank you in advance!
Upvotes: 2
Views: 1631
Reputation: 4871
These exceptions are generated by iText's CSS parser when it encounters a pseudo-class or pseudo-element that it does not (yet) support. They are simply logged (if you have a logger configured), and the selector and its declarations are ignored.
If your output is correct, you can ignore these log messages (or remove the selectors from your CSS input).
About the selectors you mention:
Those are vendor specific selectors, indicated by the -prefix-
: -moz-
is the prefix for Mozilla (Firefox), -ms-
for Microsoft (IE and Edge). Vendors use these for experimental or non-standard CSS features. It's unlikely that iText will ever support them.
Upvotes: 1