0 votes
3.4k views
in Integrations by (120 points)

1 Answer

0 votes
by (30.6k points)

Generate the document on the server in a service flow and attach it to the instance; the coach only triggers the service. Three implementations:

1. PDF with a Java library (Apache PDFBox or iText/OpenPDF as a managed server jar) called from a Java Integration; the result comes back as a Base64 string that you store with the document API:

// Java (PDFBox): build the PDF from the form data, return Base64
public static String invoice(String customer, String total) throws Exception {
  PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page);
  PDPageContentStream cs = new PDPageContentStream(doc, page);
  cs.beginText(); cs.setFont(PDType1Font.HELVETICA, 12); cs.newLineAtOffset(50, 750);
  cs.showText("Customer: " + customer); cs.newLineAtOffset(0, -20); cs.showText("Total: " + total); cs.endText(); cs.close();
  ByteArrayOutputStream out = new ByteArrayOutputStream(); doc.save(out); doc.close();
  return Base64.getEncoder().encodeToString(out.toByteArray());
}
// service flow script after the Java step: attach to the instance (BPM document store)
var props = new tw.object.listOf.ECMDocumentProperty();   // or tw.system.createDocument on older releases
tw.local.document = tw.system.createDocument("Invoice-" + tw.local.orderId + ".pdf", "application/pdf", tw.local.pdfBase64, true /*base64*/);

2. Word (.docx) from a template - docx4j or Apache POI fill placeholders in a .docx stored as a managed asset; same Java integration pattern. For letters with layout this beats generating from scratch.

3. No Java: HTML to PDF in the browser - a custom coach view renders the data as HTML and uses jsPDF / html2canvas to create the PDF client-side, then uploads it with the UI Toolkit File Uploader control (or a File Uploader bound to an ECM server). Zero server code, but fonts / page breaks are less controllable.

Attach the result: BPM document store (Document List control and the Document REST resource) or an ECM system (FileNet through the CMIS integration and the ECM File Uploader control). Send it by e-mail with the OOB Send E-Mail service plus the document attachment option (BAW 20+).

References

Related questions

0 votes
1 answer 2.4k views
0 votes
1 answer 2.6k views
0 votes
1 answer 1.7k views
0 votes
2 answers 1.8k views
0 votes
1 answer 895 views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...