Hello,
I want to write the PDF creation date in the PDF report.
When i use XSLT 2.0, XPath 2.0 with fop.bat of FOP ver 0.94, XMLSpy creates the PDF file with current date. But when i am using the same XML,XSL file to generate PDF using java method using fop.jar, it is giving NullPointerException.
Here is the code that i am using. Can someone help me what do i need to do for this?
using current-date() in XSL as inside the fo:block
<xsl:value-of select="current-date()"/>
Java Code:
I want to write the PDF creation date in the PDF report.
When i use XSLT 2.0, XPath 2.0 with fop.bat of FOP ver 0.94, XMLSpy creates the PDF file with current date. But when i am using the same XML,XSL file to generate PDF using java method using fop.jar, it is giving NullPointerException.
Here is the code that i am using. Can someone help me what do i need to do for this?
using current-date() in XSL as inside the fo:block
<xsl:value-of select="current-date()"/>
Java Code:
Code:
try {
// Setup input and output files
File xmlfile = new File("D:/XML Work/Input.xml");
File xsltfile = new File("D:/XML Work/Input.xsl");
File pdffile = new File("D:/Result_PDF.pdf");
System.out.println("Transforming...");
long st = System.currentTimeMillis();
long en = 0;
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
transformer.setParameter("versionParam", "2.0");
Source src = new StreamSource(xmlfile);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} finally {
out.close();
en = System.currentTimeMillis();
}
System.out.println("Success! --> in " + (en-st) + "ms");
} catch (Exception e) {
e.printStackTrace(System.err);
}