Hi All,
I had help from some of the great people here on the list and so I thought I'd post a solution to reading in a PDF document, changing text on a form field and then emailing it. I used iText to deal with the pdf and ERMailer to email the document. Here is my solution:
public WOComponent modifyAndEmailPDFDocument() { String myDocumentName = "Template.pdf"; try { ByteArrayOutputStream myOutputStream = new ByteArrayOutputStream(); InputStream myInputStream = WOApplication.application().resourceManager().inputStreamForResourceNamed(myDocumentName, null, NSArray.EmptyArray); PdfReader reader = new PdfReader(myInputStream); PdfStamper stamp1 = new PdfStamper(reader, myOutputStream); AcroFields form1 = stamp1.getAcroFields(); form1.setField("NameOfFormField", "text to put into form field"); stamp1.close();
NSData content = new NSData(myOutputStream.toByteArray()); ERJavaMail.sharedInstance().finishInitialization(); ERMailDeliveryPlainText message = new ERMailDeliveryPlainText(); message.setTextContent("content of email"); message.setSubject("email subject"); message.addAttachment(new ERMailDataAttachment("myattachment.pdf", null, content)); message.setToAddress("toemail"); message.setFromAddress("fromemail"); message.sendMail(); } catch (Exception ex) { System.err.println("ERROR: " + ex.getMessage()); } return context().page(); } |