我可以使用Apache fop XSL-FO为pdf添加时间戳

时间:2017-01-18 10:07:55

标签: java timestamp pdf-generation apache-fop

有没有办法使用apache fop为pdf添加时间戳。

我正在生成这样的pdf:

    final File xsltFile = new File("D:\\test.xsl");
    final StreamSource xmlSource = new StreamSource(new File("D:\\test.xml"));
    final FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
    final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

    final OutputStream out = new java.io.FileOutputStream("D:\\test.pdf");

    try {
        final Fop fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, foUserAgent, out);

        final TransformerFactory factory = TransformerFactory.newInstance();
        final Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));

        final Result res = new SAXResult(fop.getDefaultHandler());
        transformer.transform(xmlSource, res);
    } finally {
        out.close();
    }

1 个答案:

答案 0 :(得分:0)

这有帮助吗?

final FOUserAgent   foUserAgent  = FOP_FACTORY.newFOUserAgent();
/**/                foUserAgent.setProducer        ("Pro Ducer");
/**/                foUserAgent.setCreationDate    (new Date());
/**/                foUserAgent.setTargetResolution(300 /* dpi */);