/** * Returns a new FopFactory instance that is configured only by the default configuration * parameters. * * @param baseURI the base URI to resolve resource URIs against * @return the requested FopFactory instance. */ public static FopFactory newInstance(URI baseURI) { return new FopFactoryBuilder(baseURI).build(); }
/** * Returns a new FopFactory instance that is configured using the {@link FopFactoryConfig} object that * is created when the fopConf is parsed. * * @param fopConf the fop conf configuration file to parse * @return the requested FopFactory instance. * @throws IOException * @throws SAXException */ public static FopFactory newInstance(File fopConf) throws SAXException, IOException { return new FopConfParser(fopConf).getFopFactoryBuilder().build(); }
/** * Returns a new FopFactory instance that is configured using the {@link FopFactoryConfig} object that * is created when the fopConf is parsed. * * @param baseURI the base URI to resolve resource URIs against * @param confStream the fop conf configuration stream to parse * @return the requested FopFactory instance. * @throws SAXException * @throws IOException */ public static FopFactory newInstance(URI baseURI, InputStream confStream) throws SAXException, IOException { return new FopConfParser(confStream, baseURI).getFopFactoryBuilder().build(); }
/** * Generate a document, given an initialized Fop object * @param userAgent the user agent * @param outputFormat the output format to generate (MIME type, see MimeConstants) * @param out the output stream to write the generated output to (may be null if not applicable) * @throws FOPException in case of an error during processing */ public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out) throws FOPException { String baseURL = null; try { baseURL = new File(sourcefile.getAbsolutePath()) .getParentFile().toURI().toURL().toExternalForm(); } catch (Exception e) { baseURL = ""; } FopFactory factory = new FopFactoryBuilder(URI.create(baseURL)) .build(); Fop fop; if (out != null) { fop = factory.newFop(outputFormat, userAgent, out); } else { fop = factory.newFop(outputFormat, userAgent); } // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); transformTo(res); }
/** * {@inheritDoc} */ public void init() throws ServletException { this.uriResolver = new ServletContextURIResolver(getServletContext()); this.transFactory = TransformerFactory.newInstance(); transFactory.setAttribute("http://javax.xml.XMLConstants/property/accessExternalDTD", ""); transFactory.setAttribute("http://javax.xml.XMLConstants/property/accessExternalStylesheet", ""); this.transFactory.setURIResolver(this.uriResolver); //Configure FopFactory as desired // TODO: Double check this behaves properly!! ResourceResolver resolver = new ResourceResolver() { public OutputStream getOutputStream(URI uri) throws IOException { URL url = getServletContext().getResource(uri.toASCIIString()); return url.openConnection().getOutputStream(); } public Resource getResource(URI uri) throws IOException { return new Resource(getServletContext().getResourceAsStream(uri.toASCIIString())); } }; FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI(), resolver); configureFopFactory(builder); fopFactory = builder.build(); }
.build(); final String mimeType = Constants.APPLICATION_PDF; Fop fop = fopFactory.newFop(mimeType, stream);
FOPTaskStarter(Fop task) throws SAXException, IOException { this.task = task; //Set base directory if (task.getBasedir() != null) { this.baseUri = task.getBasedir().toURI(); } else { if (task.getFofile() != null) { this.baseUri = task.getFofile().getParentFile().toURI(); } } if (task.getUserconfig() != null) { FopFactoryBuilder confBuilder = new FopConfParser( task.getUserconfig()).getFopFactoryBuilder(); confBuilder.setBaseURI(baseUri); fopFactory = confBuilder.build(); } else { fopFactory = FopFactory.newInstance(baseUri); } }
factory = fopFactoryBuilder.build(); if (cacheName != null) { factory.getFontManager().setCacheFile(URI.create(cacheName));