List of usage examples for com.lowagie.text.html.simpleparser HTMLWorker parse
public void parse(Reader reader) throws IOException
From source file:ch.emad.business.schuetu.print.PrintAgent.java
License:Apache License
public void saveFileToPrint(String name, String htmlContent) { OutputStream os = null;//from w ww.j a v a 2 s . c o m try { if (!this.init) { map.put(name, htmlContent); return; } CleanerProperties props = new CleanerProperties(); // set some properties to non-default values props.setTranslateSpecialEntities(true); props.setTransResCharsToNCR(true); props.setOmitComments(true); // do parsing LOG.info("HtmlCleaner! Body wegnehmen"); TagNode tagNode = new HtmlCleaner(props).clean(htmlContent); Object[] o = tagNode.evaluateXPath("//body"); // serialize to xml file new PrettyXmlSerializer(props).writeToFile( // --> mit utf-8 wurden sonderzeichen falsch gedruckt pathprinter+"out.xml", "utf-8" (TagNode) o[0], pathprinter + "out.xml"); String outputFile = pathprinter + name + ".pdf"; os = new FileOutputStream(outputFile); Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, os); doc.open(); HTMLWorker hw = new HTMLWorker(doc); hw.parse(new FileReader(pathprinter + "out.xml")); doc.close(); if (this.applicationEventPublisher != null) { ch.emad.model.schuetu.model.integration.File file = new ch.emad.model.schuetu.model.integration.File(); file.setContent(IOUtils.toByteArray(new FileInputStream(new File(outputFile)))); file.setName(name + ".pdf"); OutgoingMessage fileOut = new OutgoingMessage(this); fileOut.setPayload(file); this.applicationEventPublisher.publishEvent(fileOut); } } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } } FileUtils.deleteQuietly(new File(pathprinter + "out.xml")); }
From source file:com.AppModel.Reportes.GeneraPdf.java
public void generarArchivoPdf(String xml) { try {//from w ww . ja v a2s .com Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("plantillaa.pdf")); document.open(); document.addAuthor("Persona creadora"); document.addCreator("Software generador"); document.addCreationDate(); document.addTitle("Titulo del documento"); HTMLWorker htmlWorker = new HTMLWorker(document); // String str = "<table>\n" // + " <tr>\n" // + " <td>Boleta</td>\n" // + " <td>Fecha</td>\n" // + " <th>Operacion</th>\n" // + " <td>Abono</td>\n" // + " <td>Interes generado </td>\n" // + " <td>Cargo</td>\n" // + " <td>Usuario que realizo el movimiento</td> \n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 15:53:37.0</td>\n" // + " <td align=center>Nuevo empeo</td>\n" // + " <td align=center></td>\n" // + " <td align=center></td>\n" // + " <td align=center>$533.00</td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 15:56:04.0</td>\n" // + " <td align=center>Extension de contrato</td>\n" // + " <td align=center></td><td align=center>$1.44</td>\n" // + " <td align=center></td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005817</td>\n" // + " <td align=center>2015-04-19 16:00:51.0</td>\n" // + " <td align=center>Desempeo</td>\n" // + " <td align=center>$554.64 </td>\n" // + " <td align=center>$21.64 </td>\n" // + " <td align=center></td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td align=center>MLOM005818</td>\n" // + " <td align=center>2015-04-19 16:37:24.0</td>\n" // + " <td align=center>Refrendo</td>\n" // + " <td align=center>$533.00 </td>\n" // + " <td align=center>$21.64 </td>\n" // + " <td align=center>$533.00 </td>\n" // + " <td align=center>admin</td>\n" // + " </tr>\n" // + " <tr>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td></td>\n" // + " <td align=center><b>$1,087.64 pesos</b> </td>\n" // + " <td align=center><b>$44.72 pesos</b> </td>\n" // + " <td align=center><b>$1,066.00 pesos</b> </td>\n" // + " </tr>\n" // + " <tr style=height:50px;>\n" // + " <td align=right colspan=7> </td>\n" // + " <td align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n" // + " <td align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n" // + " </tr>\n" // + " </table>"; String str = "<table>\n" + " <tr>\n" + " <td>Boleta</td>\n" + " <td>Fecha</td>\n" + " <th>Operacion</th>\n" + " <td>Abono</td>\n" + " <td>Interes generado </td>\n" + " <td>Cargo</td>\n" + " <td>Usuario que realizo el movimiento</td> \n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 15:53:37.0</td>\n" + " <td align=center>Nuevo empeo</td>\n" + " <td align=center></td>\n" + " <td align=center></td>\n" + " <td align=center>$533.00</td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 15:56:04.0</td>\n" + " <td align=center>Extension de contrato</td>\n" + " <td align=center></td><td align=center>$1.44</td>\n" + " <td align=center></td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005817</td>\n" + " <td align=center>2015-04-19 16:00:51.0</td>\n" + " <td align=center>Desempeo</td>\n" + " <td align=center>$554.64 </td>\n" + " <td align=center>$21.64 </td>\n" + " <td align=center></td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td align=center>MLOM005818</td>\n" + " <td align=center>2015-04-19 16:37:24.0</td>\n" + " <td align=center>Refrendo</td>\n" + " <td align=center>$533.00 </td>\n" + " <td align=center>$21.64 </td>\n" + " <td align=center>$533.00 </td>\n" + " <td align=center>admin</td>\n" + " </tr>\n" + " <tr>\n" + " <td></td>\n" + " <td></td>\n" + " <td></td>\n" + " <td align=center><b>$1,087.64 pesos</b> </td>\n" + " <td align=center><b>$44.72 pesos</b> </td>\n" + " <td align=center><b>$1,066.00 pesos</b> </td>\n" + " </tr>\n" + " <tr style=height:50px;>\n" + " <td align=right colspan=7> </td>\n" + " </tr><tr>\n" + " <td align=left colspan=5><b>El monto de apertura dia fue de: $90000.0 pesos</b> </td>\n" + " </tr><tr>\n" + " <td align=left colspan=5><b id='saldoAlCierre' title='89511.72'>Saldo al cierre: $89511.72 pesos</b> </td>\n" + " </tr>\n" + " </table>"; htmlWorker.parse(new StringReader(str)); document.close(); } catch (Exception e) { System.out.println("" + e.getMessage()); } }
From source file:com.aripd.clms.service.ContractServiceBean.java
@Override public void generatePdf(ContractEntity contract) { String baseFontUrl = "/fonts/Quivira.otf"; FontFactory.register(baseFontUrl);// w ww .j a v a 2 s. c o m ByteArrayOutputStream output = new ByteArrayOutputStream(); try { BaseFont bf = BaseFont.createFont(baseFontUrl, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font18n = new Font(bf, 18, Font.NORMAL); Font font12n = new Font(bf, 12, Font.NORMAL); Font font8n = new Font(bf, 8, Font.NORMAL); Font font8nbu = new Font(bf, 8, Font.BOLD | Font.UNDERLINE); Font font8ng = new Font(bf, 8, Font.NORMAL, Color.DARK_GRAY); Font font6n = new Font(bf, 6, Font.NORMAL); Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, output); document.open(); addMetaData(document); addTitlePage(document, contract); Image imgBlue = Image.getInstance(1, 1, 3, 8, new byte[] { (byte) 0, (byte) 0, (byte) 255, }); imgBlue.scaleAbsolute(document.getPageSize().getWidth(), 10); imgBlue.setAbsolutePosition(0, document.getPageSize().getHeight() - imgBlue.getScaledHeight()); PdfImage stream = new PdfImage(imgBlue, "", null); stream.put(new PdfName("ITXT_SpecialId"), new PdfName("123456789")); PdfIndirectObject ref = writer.addToBody(stream); imgBlue.setDirectReference(ref.getIndirectReference()); document.add(imgBlue); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Paragraph(contract.getName(), font18n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version: " + contract.getVersion(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review: " + contract.getReview(), font8n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); cell = new PdfPCell(new Paragraph(contract.getRemark(), font12n)); cell.setBorder(Rectangle.NO_BORDER); cell.setColspan(2); cell.setPadding(5); table.addCell(cell); document.add(table); // Start a new page document.newPage(); HTMLWorker htmlWorker = new HTMLWorker(document); htmlWorker.parse(new StringReader(contract.getRemark())); // Start a new page document.newPage(); document.add(new Paragraph("Review Board", font18n)); document.add(new LineSeparator(0.5f, 100, null, 0, -5)); table = new PdfPTable(3); table.setWidthPercentage(100); cell = new PdfPCell(new Paragraph("Review Board", font18n)); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Paragraph("Version", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Date", font12n)); table.addCell(cell); cell = new PdfPCell(new Paragraph("Review", font12n)); table.addCell(cell); for (HistoryContractEntity history : historyContractService.listing(contract)) { cell = new PdfPCell(new Paragraph(history.getVersion().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getStartdate().toString(), font8n)); table.addCell(cell); cell = new PdfPCell(new Paragraph(history.getReview(), font8n)); table.addCell(cell); } document.add(table); document.close(); FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.reset(); response.addHeader("Content-Type", "application/force-download"); String filename = URLEncoder.encode(contract.getName() + ".pdf", "UTF-8"); // response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + filename); response.getOutputStream().write(output.toByteArray()); response.getOutputStream().flush(); context.responseComplete(); context.renderResponse(); } catch (BadPdfFormatException | IOException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ContractServiceBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ikon.util.DocConverter.java
License:Open Source License
/** * Convert HTML to PDF/* w ww. j a v a 2 s . c om*/ */ public void html2pdf(File input, File output) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from HTML to PDF **"); FileOutputStream fos = null; try { fos = new FileOutputStream(output); // Make conversion Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, fos); doc.open(); HTMLWorker html = new HTMLWorker(doc); html.parse(new FileReader(input)); doc.close(); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:com.openkm.util.DocConverter.java
License:Open Source License
/** * Convert SRC to PDF/* w w w. j av a2 s . co m*/ */ public void src2pdf(File input, File output, String lang) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from SRC to PDF **"); FileOutputStream fos = null; FileInputStream fis = null; try { fos = new FileOutputStream(output); fis = new FileInputStream(input); // Make syntax highlight String source = IOUtils.toString(fis); JaSHi jashi = new JaSHi(source, lang); // jashi.EnableLineNumbers(1); String parsed = jashi.ParseCode(); // Make conversion to PDF Document doc = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(doc, fos); doc.open(); HTMLWorker html = new HTMLWorker(doc); html.parse(new StringReader(parsed)); doc.close(); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:MbView.MbAbonos.java
public void imprimeDespiese(Object document) { try {//from w w w. j ava 2s . c om Document pdf = (Document) document; pdf.open(); pdf.setPageSize(PageSize.A4); HTMLWorker htmlWorker = new HTMLWorker(pdf); String html = ""; html = new ImprimeDespiece().imprime(lstDespiece); htmlWorker.parse(new StringReader(html)); } catch (Exception e) { System.out.println("Ocurrio un error generando pdf: " + e.toString()); } }
From source file:org.jbpm.designer.web.server.TransformerServlet.java
License:Apache License
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String formattedSvgEncoded = req.getParameter("fsvg"); String uuid = Utils.getUUID(req); String profileName = Utils.getDefaultProfileName(req.getParameter("profile")); String transformto = req.getParameter("transformto"); String jpdl = req.getParameter("jpdl"); String gpd = req.getParameter("gpd"); String bpmn2in = req.getParameter("bpmn2"); String jsonin = req.getParameter("json"); String preprocessingData = req.getParameter("pp"); String respaction = req.getParameter("respaction"); String pp = req.getParameter("pp"); String processid = req.getParameter("processid"); String sourceEnc = req.getParameter("enc"); String convertServiceTasks = req.getParameter("convertservicetasks"); String htmlSourceEnc = req.getParameter("htmlenc"); String formattedSvg = (formattedSvgEncoded == null ? "" : new String(Base64.decodeBase64(formattedSvgEncoded), "UTF-8")); String htmlSource = (htmlSourceEnc == null ? "" : new String(Base64.decodeBase64(htmlSourceEnc), "UTF-8")); if (sourceEnc != null && sourceEnc.equals("true")) { bpmn2in = new String(Base64.decodeBase64(bpmn2in), "UTF-8"); }/*w ww .j a v a 2s .co m*/ if (profile == null) { profile = _profileService.findProfile(req, profileName); } DroolsFactoryImpl.init(); BpsimFactoryImpl.init(); Repository repository = profile.getRepository(); if (transformto != null && transformto.equals(TO_PDF)) { if (respaction != null && respaction.equals(RESPACTION_SHOWURL)) { try { ByteArrayOutputStream pdfBout = new ByteArrayOutputStream(); Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, pdfBout); pdfDoc.open(); pdfDoc.addCreationDate(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); float widthHint = getFloatParam(req, SVG_WIDTH_PARAM, DEFAULT_PDF_WIDTH); float heightHint = getFloatParam(req, SVG_HEIGHT_PARAM, DEFAULT_PDF_HEIGHT); String objStyle = "style=\"width:" + widthHint + "px;height:" + heightHint + "px;\""; t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, widthHint); t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, heightHint); ByteArrayOutputStream imageBout = new ByteArrayOutputStream(); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(imageBout); t.transcode(input, output); Image processImage = Image.getInstance(imageBout.toByteArray()); scalePDFImage(pdfDoc, processImage); pdfDoc.add(processImage); pdfDoc.close(); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); resp.getWriter() .write("<object type=\"application/pdf\" " + objStyle + " data=\"data:application/pdf;base64," + Base64.encodeBase64String(pdfBout.toByteArray()) + "\"></object>"); } catch (Exception e) { resp.sendError(500, e.getMessage()); } } else { storeInRepository(uuid, formattedSvg, transformto, processid, repository); try { resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/pdf"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".pdf\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".pdf\""); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, resp.getOutputStream()); pdfDoc.open(); pdfDoc.addCreationDate(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(bout); t.transcode(input, output); Image processImage = Image.getInstance(bout.toByteArray()); scalePDFImage(pdfDoc, processImage); pdfDoc.add(processImage); pdfDoc.close(); } catch (Exception e) { resp.sendError(500, e.getMessage()); } } } else if (transformto != null && transformto.equals(TO_PNG)) { try { if (respaction != null && respaction.equals(RESPACTION_SHOWURL)) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(bout); t.transcode(input, output); resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); if (req.getParameter(SVG_WIDTH_PARAM) != null && req.getParameter(SVG_HEIGHT_PARAM) != null) { int widthHint = (int) getFloatParam(req, SVG_WIDTH_PARAM, DEFAULT_PDF_WIDTH); int heightHint = (int) getFloatParam(req, SVG_HEIGHT_PARAM, DEFAULT_PDF_HEIGHT); resp.getWriter() .write("<img width=\"" + widthHint + "\" height=\"" + heightHint + "\" src=\"data:image/png;base64," + Base64.encodeBase64String(bout.toByteArray()) + "\">"); } else { resp.getWriter().write("<img src=\"data:image/png;base64," + Base64.encodeBase64String(bout.toByteArray()) + "\">"); } } else { storeInRepository(uuid, formattedSvg, transformto, processid, repository); resp.setContentType("image/png"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".png\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".png\""); } PNGTranscoder t = new PNGTranscoder(); t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen"); TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg)); TranscoderOutput output = new TranscoderOutput(resp.getOutputStream()); t.transcode(input, output); } } catch (TranscoderException e) { resp.sendError(500, e.getMessage()); } } else if (transformto != null && transformto.equals(TO_SVG)) { storeInRepository(uuid, formattedSvg, transformto, processid, repository); } else if (transformto != null && transformto.equals(BPMN2_TO_JSON)) { try { if (convertServiceTasks != null && convertServiceTasks.equals("true")) { bpmn2in = bpmn2in.replaceAll("drools:taskName=\".*?\"", "drools:taskName=\"ReadOnlyService\""); bpmn2in = bpmn2in.replaceAll("tns:taskName=\".*?\"", "tns:taskName=\"ReadOnlyService\""); } Definitions def = ((JbpmProfileImpl) profile).getDefinitions(bpmn2in); def.setTargetNamespace("http://www.omg.org/bpmn20"); if (convertServiceTasks != null && convertServiceTasks.equals("true")) { // fix the data input associations for converted tasks List<RootElement> rootElements = def.getRootElements(); for (RootElement root : rootElements) { if (root instanceof Process) { updateTaskDataInputs((Process) root, def); } } } // get the xml from Definitions ResourceSet rSet = new ResourceSetImpl(); rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl()); JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet .createResource(URI.createURI("virtual.bpmn2")); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8"); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true); bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD); bpmn2resource.setEncoding("UTF-8"); rSet.getResources().add(bpmn2resource); bpmn2resource.getContents().add(def); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bpmn2resource.save(outputStream, new HashMap<Object, Object>()); String revisedXmlModel = outputStream.toString(); String json = profile.createUnmarshaller().parseModel(revisedXmlModel, profile, pp); resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); resp.getWriter().print(json); } catch (Exception e) { e.printStackTrace(); _logger.error(e.getMessage()); resp.setContentType("application/json"); resp.getWriter().print("{}"); } } else if (transformto != null && transformto.equals(JSON_TO_BPMN2)) { try { DroolsFactoryImpl.init(); BpsimFactoryImpl.init(); if (preprocessingData == null) { preprocessingData = ""; } String processXML = profile.createMarshaller().parseModel(jsonin, preprocessingData); resp.setContentType("application/xml"); resp.getWriter().print(processXML); } catch (Exception e) { e.printStackTrace(); _logger.error(e.getMessage()); resp.setContentType("application/xml"); resp.getWriter().print(""); } } else if (transformto != null && transformto.equals(HTML_TO_PDF)) { try { resp.setContentType("application/pdf"); if (processid != null) { resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".pdf\""); } else { resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".pdf\""); } Document pdfDoc = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, resp.getOutputStream()); pdfDoc.open(); pdfDoc.addCreator("jBPM Designer"); pdfDoc.addSubject("Business Process Documentation"); pdfDoc.addCreationDate(); pdfDoc.addTitle("Process Documentation"); HTMLWorker htmlWorker = new HTMLWorker(pdfDoc); htmlWorker.parse(new StringReader(htmlSource)); pdfDoc.close(); } catch (DocumentException e) { resp.sendError(500, e.getMessage()); } } }