Current date in PDF

Discussion in 'XML' started by samalendu, Feb 19, 2008.

  1. samalendu

    samalendu

    Joined:
    Feb 13, 2008
    Messages:
    3
    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);
            }
    
    
    samalendu, Feb 19, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James P.
    Replies:
    7
    Views:
    12,456
    phamtasmic
    Jul 13, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,193
    Michael Borgwardt
    May 30, 2004
  3. moonhk
    Replies:
    5
    Views:
    525
    moonhk
    Oct 11, 2006
  4. Ricardo Pog
    Replies:
    1
    Views:
    395
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    337
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page