WordTemplate implements Template<E> { @Override public void toPDFDocument(E data, OutputStream out) throws IOException { PhysicalFonts.setRegex(null); prepareDocument(); TemplateContext<E> context = contextFactory.createTemplateContext(this); context.bind(data); document.updateDynamicContent(context); document.writeAsPDF(out); } WordTemplate(TemplateData template, TemplateContextFactory contextFactory); @Override void toDocument(E data, OutputStream out); @Override void toTestDocument(OutputStream out); @Override void toPDFDocument(E data, OutputStream out); @Override String getDocumentName(); @Override Class<?> getInputType(); @Override Map<String, String> getProperties(); String getLanguage(); Locale getLocale(); User getLockingUser(); Date getCreatedAt(); User getEditor(); Date getEditedAt(); @Override void update(InputStream in, User editor); @Override Map<String, MappingDetail> getContentMapping(); @Override List<String> listContentIds(); @Override void validate(); @Override void write(File file); @Override void write(OutputStream out); TemplateData getTemplateData();  }
@Test public void toPDFDocumentTest() throws IOException, Docx4JException { WordTemplate<String> wordTemplate = createWordTemplate("org/wte4j/impl/simpleTemplate.docx"); when(templateContext.resolveValue("value")).thenReturn("test123"); File generatedDocument = File.createTempFile("generated", ".pdf"); try (OutputStream out = new FileOutputStream(generatedDocument)) { wordTemplate.toPDFDocument("gugus", out); assertTrue(generatedDocument.isFile()); assertTrue(generatedDocument.length() > 0); List<String> lines = FileUtils.readLines(generatedDocument); assertTrue(lines.size() > 0); assertTrue(lines.get(0).contains("PDF")); } finally { generatedDocument.deleteOnExit(); } }