Current date in PDF

Joined
Feb 13, 2008
Messages
3
Reaction score
0
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:
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);
        }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top