Skip to Content
Author's profile photo Former Member

null exception in create pdf using FOP library(WD Java)

This is my code :

//in java class

public IWDCachedWebResource convertXML2PDF(File xml, File xslt) throws FOPException, TransformerException, IOException


            FopFactory fopFactory = FopFactory.newInstance();

            FOUserAgent foUserAgent =fopFactory.newFOUserAgent();

/* OutputStream out = new“pdffile.pdf”);

out = new;*/

               ByteArrayOutputStream out = new ByteArrayOutputStream();

                Fop fop =fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

                TransformerFactory factory =TransformerFactory.newInstance();

                Transformer transformer =factory.newTransformer(newStreamSource(xslt));

                transformer.setParameter(“versionParam”, “2.0”);

                Source src = new StreamSource(xml);

                Result res = new SAXResult(fop.getDefaultHandler());



                byte [] pdfContent = ((ByteArrayOutputStream) out).toByteArray();

                IWDCachedWebResource pdfResource = WDWebResource.getWebResource(pdfContent,WDWebResourceType.PDF);

if(pdfResource != null)

return pdfResource;

return null;

               } // end if

else   //if(transformer!=null)

System.out.print(“null exception in transformer”);

return null;


   } // end method


// in Web Dynpro code

public void ConvertXML2PDF( ) 


//@@begin ConvertXML2PDF()

File xmlfile = new File(“inputReportXML.xml”);

File xsltfile = new File(“inputReportXSL.xsl”);

CreatePDF createPDF = new CreatePDF();

try {

IWDCachedWebResource pdfResource =createPDF.convertXML2PDF( xmlfile , xsltfile);

if( pdfResource != null)

wdComponentAPI.getWindowManager().createExternalWindow( pdfResource.getURL(),“Test View”,true).open();



wdComponentAPI.getMessageManager().reportException( “PDF Resource is empty”);


catch( WDURLException e)     {


} catch (FOPException e) {


catch (TransformerException e) {



catch (IOException e) {





This is the exception that apears:

java.lang.NullPointerException: while trying to invoke the method javax.xml.transform.Transformer.setParameter(java.lang.String, java.lang.Object) of an object loaded from local variable ‘transformer’


I added inputReportXML.xml and inputReportXSL.xsl under WEB-INF Is this the true way?

  transformer.setParameter(“versionParam”, “2.0”); the exception apears because this line how i can correct this exception?


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Jun Wu
      Jun Wu
      please make the post as a discussion, not a document
      putting file in web-inf is definite wrong.
      Author's profile photo Former Member
      Former Member

      Dear Jun, Where I can putting file?