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); } }
Result res = new SAXResult(fop.getDefaultHandler());
Result res = new SAXResult(fop.getDefaultHandler());
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); } }
Result res = new SAXResult(fop.getDefaultHandler());
/** * {@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); }
/** Transform an xsl-fo StreamSource to the specified output format. * @param src The xsl-fo StreamSource instance * @param stylesheet Optional stylesheet StreamSource instance * @param fop */ public static void transform(StreamSource src, StreamSource stylesheet, Fop fop) throws FOPException { Result res = new SAXResult(fop.getDefaultHandler()); try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; if (stylesheet == null) { transformer = factory.newTransformer(); } else { transformer = factory.newTransformer(stylesheet); } transformer.setURIResolver(new LocalResolver(transformer.getURIResolver())); transformer.transform(src, res); } catch (Exception e) { throw new FOPException(e); } }
@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); } }
/** * 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 { Fop fop; if (out != null) { fop = userAgent.newFop(outputFormat, out); } else { fop = userAgent.newFop(outputFormat); } // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); transformTo(res); }
/** * @see org.pivot4j.ui.RenderCallback#startRender(org.pivot4j.ui.RenderContext) */ @Override public void startRender(TableRenderContext context) { this.fopFactory = createFopFactory(); this.userAgent = createUserAgent(fopFactory); try { Fop fop = createFop(getFopFactory(), getUserAgent(), getOutputStream()); this.documentHandler = fop.getDefaultHandler(); this.documentHandler.startDocument(); this.documentHandler.startElement(FOElementMapping.URI, "root", "root", new AttributesImpl()); startLayoutDefinition(context); endLayoutDefinition(context); startPageSequence(context); } catch (SAXException e) { throw new PivotException(e); } }