@Test public void given_aWordTemplate_whenConvertingToPdf_thenTheSamePdfIsGenerated() throws IOException, XDocReportException, PDFGenerationException { Map<String, Object> context = new HashMap<>(); context.put("test", "cegeka-batchers"); byte[] actual = pdfGeneratorService.generatePdfAsByteArray(new ClassPathResource("test_template.docx"), context); assertThat(PDDocument.load(new ByteArrayInputStream(actual))) .containsText("cegeka-batchers is working"); }
public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException { try { final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker); final IContext context = report.createContext(); context.putMap(contextMap); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final Options options = Options.getTo(PDF).via(XWPF); report.convert(context, options, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); } catch (IOException | XDocReportException e) { throw new PDFGenerationException(e); } }
PDFGeneratorService { public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException { try { final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker); final IContext context = report.createContext(); context.putMap(contextMap); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final Options options = Options.getTo(PDF).via(XWPF); report.convert(context, options, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); } catch (IOException | XDocReportException e) { throw new PDFGenerationException(e); } } }
PDFGeneratorService { public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException { try { final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker); final IContext context = report.createContext(); context.putMap(contextMap); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final Options options = Options.getTo(PDF).via(XWPF); report.convert(context, options, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); } catch (IOException | XDocReportException e) { throw new PDFGenerationException(e); } }  }
PDFGeneratorService { public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException { try { final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker); final IContext context = report.createContext(); context.putMap(contextMap); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final Options options = Options.getTo(PDF).via(XWPF); report.convert(context, options, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); } catch (IOException | XDocReportException e) { throw new PDFGenerationException(e); } }  @PostConstruct void initialize(); synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap); }
PDFGeneratorService { public synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap) throws PDFGenerationException { try { final IXDocReport report = xDocReportRegistry.loadReport(resource.getInputStream(), TemplateEngineKind.Freemarker); final IContext context = report.createContext(); context.putMap(contextMap); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final Options options = Options.getTo(PDF).via(XWPF); report.convert(context, options, byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); } catch (IOException | XDocReportException e) { throw new PDFGenerationException(e); } }  @PostConstruct void initialize(); synchronized byte[] generatePdfAsByteArray(Resource resource, Map<String, Object> contextMap);  }