Вот такой пример запускается в лотусовом агенте с приаттаченными к нему библиотеками:
avalon-framework-4.2.0.jar
batik-all-1.7.jar
common-io-1.3.1.jar
common-logging-1.0.4.jar
fop.jar
xmlgraphics-commons-1.3.1.jar
...если вдруг надо сделать на клиенте, а никаких дополнительных библиотек ему выкладывать не хочется.
Java:
import java.io.File;
import java.io_OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import lotus.domino.AgentBase;
import lotus.domino.NotesException;
import lotus.domino.Session;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fo.extensions.OldExtensionElementMapping;
import org.apache.fop.fo.extensions.svg.BatikExtensionElementMapping;
import org.apache.fop.fo.extensions.svg.SVGElementMapping;
import org.apache.fop.fo.extensions.xmp.RDFElementMapping;
import org.apache.fop.fo.extensions.xmp.XMPElementMapping;
import org.apache.fop.render.afp.extensions.AFPElementMapping;
import org.apache.fop.render.pcl.extensions.PCLElementMapping;
import org.apache.fop.render.pdf.PDFRenderer;
import org.apache.fop.render.ps.extensions.PSExtensionElementMapping;
public class JavaAgent extends AgentBase {
Session session = null;
public void NotesMain() {
try {
session = getSession();
System.out.println("FOP ExampleXML2PDF\n");
System.out.println("Preparing...");
// Setup directories
File baseDir = new File("c:/fop");
File outDir = new File(baseDir, "out");
outDir.mkdirs();
// Setup input and output files
File xmlfile = new File(baseDir, "projectteam.xml");
File xsltfile = new File(baseDir, "projectteam2fo.xsl");
File pdffile = new File(outDir, "ResultXML2PDF.pdf");
System.out.println("Input: XML (" + xmlfile + ")");
System.out.println("Stylesheet: " + xsltfile);
System.out.println("Output: PDF (" + pdffile + ")");
System.out.println();
System.out.println("Transforming...");
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.addElementMapping(new FOElementMapping());
fopFactory.addElementMapping(new SVGElementMapping());
fopFactory.addElementMapping(new BatikExtensionElementMapping());
fopFactory.addElementMapping(new ExtensionElementMapping());
// fopFactory.addElementMapping(new InternalElementMapping());
fopFactory.addElementMapping(new OldExtensionElementMapping());
fopFactory.addElementMapping(new XMPElementMapping());
fopFactory.addElementMapping(new RDFElementMapping());
fopFactory.addElementMapping(new PSExtensionElementMapping());
fopFactory.addElementMapping(new AFPElementMapping());
fopFactory.addElementMapping(new PCLElementMapping());
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
PDFRenderer pdfRenderer = new PDFRenderer();
pdfRenderer.setUserAgent(foUserAgent);
foUserAgent.setRendererOverride(pdfRenderer);
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// 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);
out.close();
System.out.println("Success!");
// (Your code goes here)
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null)
try {
session.recycle();
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
avalon-framework-4.2.0.jar
batik-all-1.7.jar
common-io-1.3.1.jar
common-logging-1.0.4.jar
fop.jar
xmlgraphics-commons-1.3.1.jar
...если вдруг надо сделать на клиенте, а никаких дополнительных библиотек ему выкладывать не хочется.
Последнее редактирование модератором: