Mauro caresimo
04/21/2023, 11:31 AMaliaspooryorik
Mauro caresimo
04/21/2023, 12:07 PMaliaspooryorik
Mauro caresimo
04/21/2023, 12:08 PMaliaspooryorik
Mauro caresimo
04/21/2023, 12:08 PMaliaspooryorik
Mauro caresimo
04/21/2023, 12:09 PMaliaspooryorik
Mauro caresimo
04/21/2023, 12:13 PMthisOldDave
04/21/2023, 12:26 PMDave Merrill
04/21/2023, 12:38 PMthisOldDave
04/21/2023, 12:46 PMprivate ByteArrayInputStream getPDFByteArray(Map<String,Object> data) throws IOException {
ByteArrayOutputStream outputPDF = new ByteArrayOutputStream();
ByteArrayInputStream inputPDF;
Map<String, Object> dataCopy = SerializationUtils.clone((HashMap<String,Object>)data);
dataCopy.put("pdfoutput", true);
Map<String,Object> fc = (Map<String,Object>)dataCopy.get("FORMCONTEXT");
if (fc != null){
fc.put("fileWorkerUrl", fileWorkerUrl);
}
String html = this.pdfTemplate.getContent(dataCopy);
Document doc =Jsoup.parse(html);
doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
doc.outputSettings().syntax(OutputSettings.Syntax.xml);
doc.outputSettings().charset("UTF-8");
ITextRenderer renderer = new ITextRenderer();
ReplacedElementFactory originalCRE = renderer.getSharedContext().getReplacedElementFactory();
ChainingReplacedElementFactory chainingReplacedElementFactory = new ChainingReplacedElementFactory();
chainingReplacedElementFactory.addReplacedElementFactory(originalCRE);
chainingReplacedElementFactory.addReplacedElementFactory(new SVGReplacedElementFactory());
renderer.getSharedContext().setReplacedElementFactory(chainingReplacedElementFactory);
renderer.setDocumentFromString(doc.outerHtml());
renderer.layout();
try {
renderer.createPDF(outputPDF);
inputPDF = new ByteArrayInputStream(outputPDF.toByteArray());
} catch (DocumentException e) {
throw new IOException(String.format(
"Failed to create pdf from: [%s] Error: [%s]",
doc.outerHtml(), e.getMessage()), e);
} finally {
IOUtils.closeQuietly(outputPDF);
}
return inputPDF;
}
In places where I am not incharge of the HTML I normally inline the css as wellthisOldDave
04/21/2023, 12:55 PMDave Merrill
04/21/2023, 1:06 PMthisOldDave
04/21/2023, 1:09 PMthisOldDave
04/21/2023, 1:09 PMDave Merrill
04/21/2023, 1:17 PMMark Takata (Adobe)
04/21/2023, 3:18 PMMark Takata (Adobe)
04/21/2023, 3:18 PM