Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
312

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 java.io.FileOutputStream("pdffile.pdf");

out = new java.io.BufferedOutputStream(out);*/

               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());

                transformer.transform(src,res);

                out.close();

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

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

if(pdfResource != null)
                {

return pdfResource;
  }
else

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();
}

else

{

wdComponentAPI.getMessageManager().reportException( "PDF Resource is empty");
}

}

catch( WDURLException e)     {

e.printStackTrace();

} catch (FOPException e) {

e.printStackTrace();}

catch (TransformerException e) {

e.printStackTrace();

}

catch (IOException e) {

e.printStackTrace();

}

  }

//************************************************************************************************************************************************

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?

Thanks,

2 Comments
Labels in this area