Guest User

Untitled

a guest
Aug 10th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public static ByteArrayInputStream allPersonsReport(List<Person> persons) {
  2.  
  3. Document document = new Document(PageSize.LEGAL.rotate());
  4. ByteArrayOutputStream out = new ByteArrayOutputStream();
  5.  
  6. try {
  7. ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
  8. templateResolver.setSuffix(".html");
  9. templateResolver.setTemplateMode("HTML");
  10.  
  11. TemplateEngine templateEngine = new TemplateEngine();
  12. templateEngine.setTemplateResolver(templateResolver);
  13.  
  14. Context context = setContextAllPerson(persons);
  15.  
  16. String html = templateEngine.process("templates/report_all_persons", context);
  17.  
  18. PdfWriter writer = PdfWriter.getInstance(document, out);
  19. document.open();
  20. InputStream is = new ByteArrayInputStream(html.getBytes());
  21. XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
  22. document.close();
  23. out.close();
  24. } catch (DocumentException ex) {
  25. Logger.getLogger(GeneratePdfReport.class.getName()).log(Level.SEVERE, null, ex);
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. return new ByteArrayInputStream(out.toByteArray());
  30. }
Add Comment
Please, Sign In to add comment