Hello,
Does anyone know how to add JavaScript to a PDF file with the Apache FOP framework?
We are already generating PDF files from our application which are presented to the user. But in addition to that we want to include the option to automatically print the document when it opens.
After a lot of googling the only useful site we found was this: http://xmlgraphics.apache.org/fop/dev/design/extending.html
It describes that you can make PDF additions with an XML Document Extension.
<my:script-link script="app.execMenuItem('AcroSrch:Query');">
Search
</my:script-link>
But we couldn't find any Java examples using this XML Document Extensions..
Anyone who has some ideas on this?
Here is a small code example form our application which produces the PDF files:
OutputStream out = new FileOutputStream(file);
try
{
Fop fop = fopFactory.newFop(mimeType, out);
// Setup JAXP using identity transformer
Transformer transformer = getTransformer("/xhtml2fo.xsl");
// transformer
// Setup input stream
Source src = new DOMSource(foDocument);
// Resulting SAX events (the generated FO) must be piped through to
// FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
catch (Exception ex)
{
LOG.error("Fout bij het genereren van PDF", ex);
}