/** * @param factory * @param agent * @param out * @return * @throws FOPException */ protected Fop createFop(FopFactory factory, FOUserAgent agent, OutputStream out) throws FOPException { return factory.newFop(getContentType(), agent, out); }
private ContentHandler getFOPContentHandler(OutputStream out) throws FOPException { Fop fop = fopFactory.newFop(this.outputMime, out); return fop.getDefaultHandler(); }
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); } }
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
public void export(OutputStream out) throws FOPException, IOException, TransformerException { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); // Setup XSLT TransformerFactory Factory = TransformerFactory.newInstance(); Transformer transformer = Factory.newTransformer(xsltSource); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Reader reader = composeXml(); Source src = new StreamSource(reader); // 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); reader.close(); out.flush(); }
public void export(OutputStream out) throws FOPException, IOException, TransformerException { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); // Setup XSLT TransformerFactory Factory = TransformerFactory.newInstance(); Transformer transformer = Factory.newTransformer(xsltSource); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Reader reader = composeXml(); Source src = new StreamSource(reader); // 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); reader.close(); out.flush(); }
public void export(OutputStream outputStream) throws FOPException, IOException, TransformerException { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, outputStream); // Setup XSLT TransformerFactory Factory = TransformerFactory.newInstance(); Transformer transformer = Factory.newTransformer(xsltSource); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Reader reader = composeXml(); Source src = new StreamSource(reader); // 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); reader.close(); outputStream.flush(); }
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())); }
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);
public void export(OutputStream outputStream) throws FOPException, IOException, TransformerException { FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI()); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, outputStream); // Setup XSLT TransformerFactory Factory = TransformerFactory.newInstance(); Transformer transformer = Factory.newTransformer(xsltSource); // Set the value of a <param> in the stylesheet transformer.setParameter("versionParam", "2.0"); // Setup input for XSLT transformation Reader reader = composeXml(); Source src = new StreamSource(reader); // 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); reader.close(); outputStream.flush(); }
/** * <p>render</p> * * @param in a {@link java.io.Reader} object. * @param out a {@link java.io.OutputStream} object. * @param xslt a {@link java.io.Reader} object. * @throws org.opennms.reporting.availability.render.ReportRenderException if any. */ public void render(final Reader in, final OutputStream out, final Reader xslt) throws ReportRenderException { try { final FopFactory fopFactory = FopFactory.newInstance(); fopFactory.setStrictValidation(false); final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); final TransformerFactory tfact = TransformerFactory.newInstance(); final Transformer transformer = tfact.newTransformer(new StreamSource(xslt)); transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name()); final StreamSource streamSource = new StreamSource(in); transformer.transform(streamSource, new SAXResult(fop.getDefaultHandler())); } catch (final Exception e) { throw new ReportRenderException(e); } }
/** * <p>render</p> * * @param in a {@link java.io.Reader} object. * @param out a {@link java.io.OutputStream} object. * @param xslt a {@link java.io.Reader} object. * @throws org.opennms.reporting.availability.render.ReportRenderException if any. */ public void render(final Reader in, final OutputStream out, final Reader xslt) throws ReportRenderException { try { final FopFactory fopFactory = FopFactory.newInstance(); fopFactory.setStrictValidation(false); final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); final TransformerFactory tfact = TransformerFactory.newInstance(); final Transformer transformer = tfact.newTransformer(new StreamSource(xslt)); transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name()); final StreamSource streamSource = new StreamSource(in); transformer.transform(streamSource, new SAXResult(fop.getDefaultHandler())); } catch (final Exception e) { throw new ReportRenderException(e); } }
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outputStream);
/** * {@inheritDoc} */ protected void render(Source src, Transformer transformer, HttpServletResponse response) throws FOPException, TransformerException, IOException { FOUserAgent foUserAgent = getFOUserAgent(); //Setup FOP Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent); //Make sure the XSL transformation's result is piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); //Start the transformation and rendering process transformer.transform(src, res); //Return the result reportOK(response); }
/** 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; }
@Override public void setOutputStream(OutputStream outputStream) { try { Fop fop = FOP_FACTORY.newFop(this.outputFormat, outputStream); ContentHandler fopContentHandler = fop.getDefaultHandler(); this.setContentHandler(fopContentHandler); } catch (FOPException e) { throw new ProcessingException("Impossible to initialize FOPSerializer", e); } }
@Override public void setOutputStream(final OutputStream outputStream) { try { Fop fop = FOP_FACTORY.newFop(this.outputFormat, outputStream); ContentHandler fopContentHandler = fop.getDefaultHandler(); this.setContentHandler(fopContentHandler); } catch (FOPException e) { throw new ProcessingException("Impossible to initialize FOPSerializer", e); } }
/** * Returns a new {@link Fop} instance. Use this factory method if you want to supply your * own {@link org.apache.fop.render.Renderer Renderer} or * {@link org.apache.fop.fo.FOEventHandler FOEventHandler} * instance instead of the default ones created internally by FOP. * @param userAgent the user agent that will be used to control the rendering run * @return the new Fop instance * @throws FOPException when the constructor fails */ public Fop newFop(FOUserAgent userAgent) throws FOPException { if (userAgent.getRendererOverride() == null && userAgent.getFOEventHandlerOverride() == null && userAgent.getDocumentHandlerOverride() == null) { throw new IllegalStateException("An overriding renderer," + " FOEventHandler or IFDocumentHandler must be set on the user agent" + " when this factory method is used!"); } return newFop(null, userAgent); }