daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top