/** @return a new FOUserAgent for FOP */ protected FOUserAgent getFOUserAgent() { FOUserAgent userAgent = fopFactory.newFOUserAgent(); //Configure foUserAgent as desired return userAgent; }
/** * @see com.isotrol.impe3.palette.pdf.fop.FopService#newUserAgent() */ public FOUserAgent newUserAgent() { return fopFactory.newFOUserAgent(); }
/** * @param factory * @return */ protected FOUserAgent createUserAgent(FopFactory factory) { return factory.newFOUserAgent(); }
// configure fopFactory as desired FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); fopFactory.setUserConfig(new File("fop.xml"));
/** * Returns a new {@link Fop} instance. FOP will be configured with a default user agent * instance. * <p> * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @return the new Fop instance * @throws FOPException when the constructor fails */ public Fop newFop(String outputFormat) throws FOPException { return newFOUserAgent().newFop(outputFormat); }
/** * Returns a new {@link Fop} instance. FOP will be configured with a default user agent * instance. Use this factory method if your output type requires an output stream. * <p> * MIME types are used to select the output format (ex. "application/pdf" for PDF). You can * use the constants defined in {@link MimeConstants}. * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). * @param stream the output stream * @return the new Fop instance * @throws FOPException when the constructor fails */ public Fop newFop(String outputFormat, OutputStream stream) throws FOPException { return newFOUserAgent().newFop(outputFormat, stream); }
FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent userAgent = fopFactory.newFOUserAgent(); TransformerFactory factory = org.apache.xalan.processor.TransformerFactoryImpl.newInstance(); Transformer transformer; OutputStream out = new BufferedOutputStream(pdfOut[0].setBinaryStream(1L)); try { Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG /* or MIME_TIFF */, userAgent, out); transformer = factory.newTransformer(new StreamSource(xsltIn.getCharacterStream())); Source src = new StreamSource(xmlIn.getCharacterStream()); Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); } catch ...
public void generatePdf(final StreamSource source, final File outputFile) throws IOException, FOPException, TransformerException { try (final FileOutputStream fOut = new FileOutputStream(outputFile); final BufferedOutputStream bOut = new BufferedOutputStream(fOut)) { FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, bOut); final TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); // identity transformer // Resulting SAX events (the generated FO) must be piped through to FOP final Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(source, res); } }
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
public void fopReport(OutputStream pdfOut, OutputStream jpgOut, Source xmlSource, Source xsltSource) throws Exception { // Create the FO content TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(xsltSource); ByteArrayOutputStream foBytesStream = new ByteArrayOutputStream(); StreamResult foByteStreamResult = new StreamResult(foBytesStream); transformer.transform(xmlSource, foByteStreamResult); byte[] foBytes = foBytesStream.toByteArray(); // Render twice FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent uaPDF = fopFactory.newFOUserAgent(); FOUserAgent uaJpg = fopFactory.newFOUserAgent(); Fop fopPDF = fopFactory.newFop(MimeConstants.MIME_PDF, uaPDF, pdfOut); Fop fopJpg = fopFactory.newFop(MimeConstants.MIME_JPEG, uaJpg, jpgOut); //PDF Source src = new StreamSource(new ByteArrayInputStream(foBytes)); Transformer resultTransformer = factory.newTransformer(); resultTransformer.transform(src, new SAXResult(fopPDF.getDefaultHandler())); //JPF src = new StreamSource(new ByteArrayInputStream(foBytes)); resultTransformer = factory.newTransformer(); resultTransformer.transform(src, new SAXResult(fopJpg.getDefaultHandler())); }
private static FOUserAgent getDefaultUserAgent( File fo, String resourceDir ) { FOUserAgent foUserAgent = FOP_FACTORY.newFOUserAgent(); foUserAgent.setBaseURL( getBaseURL( fo, resourceDir ) ); return foUserAgent; }
FopFactory fopFactory = FopFactory.newInstance(); FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); AWTRenderer renderer = new AWTRenderer(); renderer.setPreviewDialogDisplayed(false); foUserAgent.setRendererOverride(renderer); renderer.setUserAgent(foUserAgent); PreviewDialog previewDlg = PreviewDialog.createPreviewDialog(foUserAgent, null, false); renderer.setStatusListener(previewDlg); renderer.clearViewportList(); TransformerFactory transformFactory = TransformerFactory.newInstance(); Transformer transformerFo = transformFactory.newTransformer(new StreamSource(xslt)); FileOutputStream fileoutFo = new FileOutputStream(tempFoFile); BufferedOutputStream outFo = new BufferedOutputStream(fileoutFo); transformerFo.transform (new StreamSource(xml),new StreamResult(outFo)); Transformer transformerPdf = transformFactory.newTransformer(); FileOutputStream fileoutPdf = new FileOutputStream(tempPdfFile); BufferedOutputStream outPdf = new BufferedOutputStream(fileoutPdf); final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outPdf); Source srcPdf = new StreamSource(fo); Result resPdf = new SAXResult(fop.getDefaultHandler()); transformerPdf.transform(srcPdf, resPdf);
private void renderInputHandler(InputHandler inputHandler, File outFile, String outputFormat) throws Exception { OutputStream out = null; try { out = new java.io.FileOutputStream(outFile); out = new BufferedOutputStream(out); } catch (Exception ex) { throw new BuildException("Failed to open " + outFile, ex); } boolean success = false; try { FOUserAgent userAgent = fopFactory.newFOUserAgent(); inputHandler.renderTo(userAgent, outputFormat, out); success = true; } catch (Exception ex) { if (task.getThrowexceptions()) { throw new BuildException(ex); } throw ex; } finally { try { out.close(); } catch (IOException ioe) { logger.error("Error closing output file", ioe); } if (!success) { outFile.delete(); } } }
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); try { TransformerFactory factory = TransformerFactory.newInstance();
@Override public void run() { OutputStream outstream = null; try { InputHandler input = new InputHandler(inputFile); FOUserAgent userAgent = FopFactory.newInstance().newFOUserAgent(); userAgent.setBaseURL(resourceBaseDir); outstream = new BufferedOutputStream(new FileOutputStream(outputFile)); input.renderTo(userAgent, MimeConstants.MIME_PDF, outstream); logger.info("Successfully rendered {}", outputFile); } catch (Exception e) { logger.error("Unknown Exception in FOP", e); throw new RuntimeException(e); } finally { try { if (outstream != null) outstream.close(); } catch (Exception e) { logger.error("Unknown Exception in FOP", e); } } } }
protected void transformToStream(InputStream templateStream, ParamsTree<String, String> documentParams, OutputStream outStream) throws ExportServiceException { // the XML file from which we take the name Source source = this.mapParamsToSource(documentParams); // creation of transform source StreamSource transformSource = new StreamSource(templateStream); // create an instance of fop factory FopFactory fopFactory = FopFactory.newInstance(); // a user agent is needed for transformation FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); // to store output try { Transformer xslfoTransformer = this.getTransformer(transformSource); // Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outStream); // Resulting SAX events (the generated FO) // must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing // everything will happen here.. xslfoTransformer.transform(source, res); } catch (FOPException e) { FOPPDFTransformer.log.error(e.getMessage(), e); throw new ExportServiceException("Error using FOP to open the template", e); } catch (TransformerException e) { FOPPDFTransformer.log.error(e.getMessage(), e); throw new ExportServiceException("Error generating pdf from template and data source", e); } }
private FontInfo setupFonts(FopFactory fopFactory, String mime, FontEventListener listener) throws FOPException { FOUserAgent userAgent = fopFactory.newFOUserAgent(); //The document handler is only instantiated to get access to its configurator! IFDocumentHandler documentHandler = fopFactory.getRendererFactory().createDocumentHandler(userAgent, mime); IFDocumentHandlerConfigurator configurator = documentHandler.getConfigurator(); FontInfo fontInfo = new FontInfo(); configurator.setupFontInfo(documentHandler.getMimeType(), fontInfo); documentHandler.setFontInfo(fontInfo); return fontInfo; }
/** Returns a new Fop instance. Note: FOP documentation recommends using * a Fop instance for one transform run only. * @param out The target (result) OutputStream instance * @param outputFormat Optional output format, defaults to "application/pdf" * @param foUserAgent FOUserAgent object which may contains encryption-params in render options * @return Fop instance */ public static Fop createFopInstance(OutputStream out, String outputFormat, FOUserAgent foUserAgent) throws FOPException { if (UtilValidate.isEmpty(outputFormat)) { outputFormat = MimeConstants.MIME_PDF; } if (UtilValidate.isEmpty(foUserAgent)) { FopFactory fopFactory = getFactoryInstance(); foUserAgent = fopFactory.newFOUserAgent(); } Fop fop; if (out != null) { fop = fopFactory.newFop(outputFormat, foUserAgent, out); } else { fop = fopFactory.newFop(outputFormat, foUserAgent); } return fop; }