Recently one of our Opentext MBPM customers asked us how to produce a PDF document from data entered into a Rich Text control. We have implemented this functionality into other Metastorm processes in the past and today I thought it would be a good time to share with you a little snippet to get you started.
.Net PDF Library
There are multiple .Net libraries available on the market to create PDF documents. We have worked successfully with Aspose and iTextSharp on several projects. The snippet we share with you is using the free available iTextSharp library. If you want to take our snippet further you can find many samples how to use the library by searching for "iTextSharp" with the search engine of your choice.
Richt Text to PDF
The Rich Text control has been added to Metastorm in version 9. The Metastorm Rich Text control allows content to be edited, formatted and spell-checked for English, French, and German languages. The control is supplied with a toolbar containing a set of options which provide basic editing functionality such as cut, copy, paste, find and replace, undo/redo etc. The Rich Text control is usuall bound to a Memo variable and its content is stored as HTML.
In order to produce a PDF document from this HTML content it is required to pass the variable content to a function which then produces the PDF, in this sample, with the iTextSharp .Net library. Follow the 3 simple steps to get started:
1.) Copy .Net Library
Copy the iTextSharp.dll file into the following locations:
2.) Create Server Side Script
A sample implementation of the method could look like the following:
public static void CreatePDF(string text, string SaveAs)
iTextSharp.text.Document document = new iTextSharp.text.Document();
iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(SaveAs, FileMode.Create));
iTextSharp.text.html.simpleparser.HTMLWorker hw =
Make sure you add the System.IO namespace to your Server Side Script in order for the sample code to work.
3.) Use the CreatePDF method
The above Server Side Script code will promote the method in the MBPM Designer Expression Builder and the Visual Script Toolbox and allows HTML code to be saved as a PDF document on the file system. The last step would be to select this method from the Expression Build or drag the Create PDF activity into your Visual Script in one of the Event Handler e.g. "When Button Pressed".
I hope you can take some useful information away. As always we would like hear your thoughts on this. You can download the full OpenText MBPM 9.3 Solution (including the iTextSharp.dll) below:
Any questions regarding this please feel free to contact us directly.