I’m trying to use fop 1.1 library to covert a xml file to pdf with the fop library on webMethods 8.0.
The code I am using is quite basic, it’s actually the sample code from the fop home page except I have the xml data in a string rather than reading it from a file. I put all the jars file in the package/code/jars folder.
I keep getting the the following error:
The code is as follows:
IDataCursor idc = pipeline.getCursor();
String xmlString = IDataUtil.getString( idc, "xmlData" );
String xsltString = IDataUtil.getString ( idc, "xsltData" );
ByteArrayOutputStream out = new ByteArrayOutputStream();
FopFactory fopFactory = FopFactory.newInstance();
TransformerFactory tFactory = TransformerFactory.newInstance();
Source xml = new StreamSource( new StringReader( xmlString ) );
Source xslt = new StreamSource( new StringReader( xsltString ) );
try{
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.getRendererOptions();
Fop fop = fopFactory.newFop( MimeConstants.MIME_PDF, foUserAgent, out );
Transformer transformer = tFactory.newTransformer( xslt );
Result res = new SAXResult( fop.getDefaultHandler() );
transformer.transform( xml, res );
}
catch( FOPException e ){
IDataUtil.put( idc, "errorMessage", e.getMessage() );
}
finally{
idc.destroy();
}
Does anybody have any experience with using the fop 1.1 library on a webMethods server and could perhaps let me know where my problem lies.
I actually haven’t been able to solve this problem yet, I’m still getting the same error. I’m wondering if there is a clash between libraries in server but haven’t been able to verify that yet. There is a older package on the server which uses a older version of Fop, however when I tried using the Fop 1.1 on a newly set up Wm 9.5 server I got the same error so if there is a clash of libraries its between something built into the IS.
I managed to get the transformer to run and produce a pdf file by adding the following code:
This issue has now been resolved by adding the libraries to the Java ClassPath on the server, that is putting them into the
[b][install directory]\IntegrationServer\lib\jars[/b]
folder and restarting the server.
i was able to write the file into Integration server directory.
but if try to send this file as a mail attachment ,the resulting PDF file seems to be corrupted.
i am passing PDF content as bytes to attachments/content and setting the ContentType =application/pdf.
Guys, I am using fop 2.2. I used following code (very much the same as what Brynjolfur shared above, but I get NullPointerException from the last line "transformer.transform( xml, res ). The xml and res objects are not null. What could be causing this error?