XI: Generate PDF file out of file adapter
While going through the SDN forum, I saw, some of us wanted to know how to generate a PDF file out of receiver file adapter in XI. While ideas from other SDN members include Java mapping or proxies, here we will see how to use the Module Processor to do the conversion job.
The advantage of using module processor exit is its flexibility to take variables in configuration, instead of hard coding as with mapping program or proxies
In the below example, we receive a simple XML file and transform it to XSL FO format using XSLT mapping. Then we use FOP (download source from Apache FOP ) for converting the XSL-FO to PDF format
Design
Target schema is available in the source FOP directory srcfoschema, which was downloaded from apache.org. But this needs to be tweaked to upload successfully in XI. You can download the tweaked version from FOP XSD
Configuration
On the receiver file adapter, we will use a module processor exit bean. The code snippet for the processor bean is provided below
public ModuleData process( ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException { Object obj = null; Message msg = null; try { obj = inputModuleData.getPrincipalData(); msg = (Message) obj; XMLPayload xmlpayload = msg.getDocument(); if (xmlpayload != null) { byte by[] = convert(xmlpayload); xmlpayload.setContent(by); } } catch (Exception e) { ModuleException me = new ModuleException(e); throw me; } return inputModuleData; } public byte[] convert(XMLPayload xmlpayload) throws Exception { byte[] content = null; try { Driver driver = new Driver(); driver.setRenderer(Driver.RENDER_PDF); ByteArrayOutputStream out = new ByteArrayOutputStream(); driver.setOutputStream(out); driver.setInputSource(new InputSource(xmlpayload.getInputStream())); driver.run(); content = out.toByteArray(); } catch (Exception e) {} //return xmldata.getBytes(); return content; }
This module references the following jar files fop.jar, avalon-framework-cvs-20020806.jar, batik.jar, xalan-2.4.1.jar, xercesImpl-2.2.1.jar and xml-apis.jar. These jar files are available in the build and lib directory of FOP download
That’s it. You are now ready to test your interface. Data transfer using PDF offers various benefits on security and data integrity. By using Java cryptology, you can also encrypt the PDF file and secure it with a password for additional security
In my next blog, I will talk about how to build a module for reading content from a PDF file, in the sender adapter
Best regards,
Felix
KK
I am not sure if this is the right place to ask the doubt.
Assuming a i convert a existing pdf file into xml format and pass that to function module in form of string. is it possible to recreate the pdf with same formatting structure in backend.
i am creating pdf using itext and then reading the pdf and converting it into xml and then passing the xml file as string. The round about way is so since i am using it mobile infrastructure based scenario and i can only pass string to the r3. please let me know if the following is possible
If you cannot use XSTRING in your RFC, you can still convert the binary data to string (use proper encoding) in your java mapping . Once within RFC module you could standard function module SCMS_STRING_TO_XSTRING to convert the PDF string to XSTRING to get your PDF data.
Hope this helps
KK
Regards
Ganesh
Check this link out.
http://help.sap.com/saphelp_nw04s/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
You need to use XSLT mapping and the above link will guide you how to do it.
KK
Iam using NWDS as development env.
I created a Java project and added the jars mentioned in the blog. But still am getting errors for Message and ModuleData process......the very first line. Also let me what should i give in IR,ID.
Thanks a lot,
regards,
Ganesh
Check this link -> https://websmp107.sap-ag.de/~sapdownload/011000358700003237612005E/HowToCreateAdapterModules.pdf
It gives step by step instruction on how to create a adapter module in NWDS and deploying it.
Thanks
KK
I have a question regarding the configuration in Integration Directory. Which entries I have to make in the file receiver communication channel in the modul configuration?
Have I to create an own module (with fop.jar etc.) and deploy it with JSPM (we have PI 7.11)?
Thanks and best regards!
Christopher Kühn
there is an implementation of a FOP module here:
http://www.java4less.com/fopdesigner/fodesigner.php?info=sappi
either you can use it as it is or it can inspire you how to create your own module.
regards
Jon