0

I need to generate a PDF using Flying Saucer. Is it possible to insert EL expressions in the PDF template, load the file, pass to a EL compiler with a Map<String, Object> as a context, and let the compiler transform the template to a compiled String, with the EL expression evaluated from the passed context? Something like this:

src/WebContent/test.xhtml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
    <div>Hello #{name}</div>
</body>

</html>

Java pseudocode:

Compiler compiler = new ElCompiler();
Map<String, Object> data = new HashMap<>();
data.put("name", "World!");
String template = compiler.apply("test.xhtml", data);
Marco Sulla
  • 15,299
  • 14
  • 65
  • 100
  • EL might work for you, but have a look at http://freemarker.org/ as well – Jasper de Vries Aug 26 '21 at 15:04
  • @JasperdeVries: I know Freemarker, is very good, but in the end I chose Handlebars. I was searching an alternative to Handlebars because I thought it can't check equality, but this is not true, thank to Helpers! Thank you anyway :) – Marco Sulla Aug 26 '21 at 15:15

0 Answers0