當前位置: 首頁>>代碼示例>>Java>>正文


Java Fop類代碼示例

本文整理匯總了Java中org.apache.fop.apps.Fop的典型用法代碼示例。如果您正苦於以下問題:Java Fop類的具體用法?Java Fop怎麽用?Java Fop使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Fop類屬於org.apache.fop.apps包,在下文中一共展示了Fop類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import org.apache.fop.apps.Fop; //導入依賴的package包/類
protected void render(FopFactory fopFactory, FOUserAgent foUserAgent, String outputFormat, Source foDocumentSrc, PlaceholderReplacementHandler.PlaceholderLookup placeholderLookup, OutputStream outputStream) throws Docx4JException {
	Fop fop = null;
	Result result = null;
	try {
		if (foUserAgent==null) {
			fop = fopFactory.newFop(outputFormat, outputStream);
		} else {
			fop = fopFactory.newFop(outputFormat, foUserAgent, outputStream);				
		}
		result = (placeholderLookup == null ?
				//1 Pass
				new SAXResult(fop.getDefaultHandler()) :
				//2 Pass
				new SAXResult(new PlaceholderReplacementHandler(fop.getDefaultHandler(), placeholderLookup)));
	} catch (FOPException e) {
		throw new Docx4JException("Exception setting up result for fo transformation: " + e.getMessage(), e);
	}
	
	XmlSerializerUtil.serialize(foDocumentSrc, result, false, false);
}
 
開發者ID:plutext,項目名稱:docx4j-export-FO,代碼行數:21,代碼來源:FORendererApacheFOP.java

示例2: createFopInstance

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/** 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;
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:24,代碼來源:ApacheFopWorker.java

示例3: export

import org.apache.fop.apps.Fop; //導入依賴的package包/類
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();
}
 
開發者ID:ManyDesigns,項目名稱:Portofino,代碼行數:27,代碼來源:FormPdfExporter.java

示例4: render

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/**
 * <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(Reader in, OutputStream out, Reader xslt) throws ReportRenderException {
    try {

        FopFactory fopFactory = FopFactory.newInstance();
        fopFactory.setStrictValidation(false);
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

        TransformerFactory tfact = TransformerFactory.newInstance();
        Transformer transformer = tfact.newTransformer(new StreamSource(xslt));
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        transformer.transform(new StreamSource(in), new SAXResult(fop.getDefaultHandler()));

    } catch (TransformerConfigurationException tce) {
        log.fatal("TransformerConfigurationException", tce);
        throw new ReportRenderException(tce);
    } catch (TransformerException te) {
        log.fatal("TransformerException", te);
        throw new ReportRenderException(te);
    } catch (FOPException e) {
        log.fatal("FOPException", e);
        throw new ReportRenderException(e);
    }
}
 
開發者ID:vishwaabhinav,項目名稱:OpenNMS,代碼行數:32,代碼來源:PDFReportRenderer.java

示例5: export

import org.apache.fop.apps.Fop; //導入依賴的package包/類
public void export(OutputStream out) throws FOPException, IOException, TransformerException {
    FopFactory fopFactory = FopFactory.newInstance();

    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();
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:27,代碼來源:FormPdfExporter.java

示例6: toPDF

import org.apache.fop.apps.Fop; //導入依賴的package包/類
public void toPDF(OutputStream os) {
    try {
        FOUserAgent userAgent = FopFactory.newInstance().newFOUserAgent();
        Fop fop = FopFactory.newInstance().newFop(MimeConstants.MIME_PDF, userAgent, os);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();

        Source src = new StreamSource(new StringReader(fo));
        Result res = new SAXResult(fop.getDefaultHandler());

        transformer.transform(src, res);
    }
    catch (FOPException fope) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{fope.getMessage()});
    }
    catch (TransformerConfigurationException tce) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{tce.getMessage()});
    }
    catch (TransformerException te) {
        LOGGER.log(Level.SEVERE, "{0}", new Object[]{te.getMessage()});
    }
}
 
開發者ID:akullpp,項目名稱:fopdf,代碼行數:23,代碼來源:Builder.java

示例7: resolveView

import org.apache.fop.apps.Fop; //導入依賴的package包/類
public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception {
    InputStream is = new ByteArrayInputStream(((String) viewData).getBytes("UTF-8"));
    
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    
    FopFactory fopFactory = FopFactory.newInstance();
    fopFactory.setStrictValidation(false);
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
    
    TransformerFactory tfact = TransformerFactory.newInstance();
    Transformer transformer = tfact.newTransformer();
    Source src = new StreamSource(is);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);
    
    byte[] contents = out.toByteArray();
    response.setContentLength(contents.length);
    response.getOutputStream().write(contents);

}
 
開發者ID:qoswork,項目名稱:opennmszh,代碼行數:22,代碼來源:OnmsPdfViewResolver.java

示例8: testFO2RTFWithJAXP

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/**
 * Tests Fop with JAXP and OutputStream generating RTF.
 * @throws Exception if anything fails
 */
@Test
public void testFO2RTFWithJAXP() throws Exception {
    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);

    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(); //Identity transf.
    Source src = new StreamSource(foFile);
    Result res = new SAXResult(fop.getDefaultHandler());
    transformer.transform(src, res);

    assertTrue("Generated RTF has zero length", baout.size() > 0);
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:20,代碼來源:BasicDriverTestCase.java

示例9: readInput

import org.apache.fop.apps.Fop; //導入依賴的package包/類
protected void readInput(PipelineContext context, ProcessorInput input, Config config, OutputStream outputStream) {
    try {
        // Setup FOP to output PDF
        final FopFactory fopFactory = FopFactory.newInstance();
        final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

        final URL configFileUrl = this.getClass().getClassLoader().getResource("fop-userconfig.xml");
        if (configFileUrl == null) {
            logger.warn("FOP config file not found. Please put a fop-userconfig.xml file in your classpath for proper display of UTF-8 characters.");
        } else {
            final File userConfigXml = new File(configFileUrl.getFile());
            fopFactory.setUserConfig(userConfigXml);
        }

        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outputStream);

        // Send data to FOP
        readInputAsSAX(context, INPUT_DATA, new ForwardingXMLReceiver(fop.getDefaultHandler()));
    } catch (Exception e) {
        throw new OXFException(e);
    }
}
 
開發者ID:evlist,項目名稱:orbeon-forms,代碼行數:23,代碼來源:XSLFOSerializer.java

示例10: render

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/**
 * Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP
 * transformer given to optionally transform the input document to XSL-FO.
 * The transformer may be an identity transformer in which case the input
 * must already be XSL-FO. The PDF is written to a byte array that is
 * returned as the method's result.
 * @param src Input XML or XSL-FO
 * @param transformer Transformer to use for optional transformation
 * @param response HTTP response object
 * @throws FOPException If an error occurs during the rendering of the
 * XSL-FO
 * @throws TransformerException If an error occurs during XSL
 * transformation
 * @throws IOException In case of an I/O problem
 */
public void render(Source src, Transformer transformer, HttpServletResponse response, String realpath)
            throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent(realpath);

    //Setup output
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    //Setup FOP
    fopFactory.setBaseURL(realpath);
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);


    //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
    sendPDF(out.toByteArray(), response);
}
 
開發者ID:malglam,項目名稱:Lester,代碼行數:38,代碼來源:CreatePDF.java

示例11: transform

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/** 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);
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:22,代碼來源:ApacheFopWorker.java

示例12: transform

import org.apache.fop.apps.Fop; //導入依賴的package包/類
@Override
public void transform(MCRContent input, OutputStream out) throws TransformerException, IOException {
    try {
        final FOUserAgent userAgent = fopFactory.newFOUserAgent();
        userAgent.setProducer(MessageFormat.format("MyCoRe {0} ({1})", MCRCoreVersion.getCompleteVersion(),
            userAgent.getProducer()));

        final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
        final Source src = input.getSource();
        final Result res = new SAXResult(fop.getDefaultHandler());
        Transformer transformer = getTransformerFactory().newTransformer();
        transformer.transform(src, res);
    } catch (FOPException e) {
        throw new TransformerException(e);
    } finally {
        out.close();
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:19,代碼來源:MCRFoFormatterFOP.java

示例13: transform

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/** Transform an xsl-fo file to the specified file format.
 * @param srcFile The xsl-fo File instance
 * @param destFile The target (result) File instance
 * @param stylesheetFile Optional stylesheet File instance
 * @param outputFormat Optional output format, defaults to "application/pdf"
 */
public static void transform(File srcFile, File destFile, File stylesheetFile, String outputFormat) throws IOException, FOPException {
    StreamSource src = new StreamSource(srcFile);
    StreamSource stylesheet = stylesheetFile == null ? null : new StreamSource(stylesheetFile);
    BufferedOutputStream dest = new BufferedOutputStream(new FileOutputStream(destFile));
    Fop fop = createFopInstance(dest, outputFormat);
    if (fop.getUserAgent().getBaseURL() == null) {
        String baseURL = null;
        try {
            File parentFile = new File(srcFile.getAbsolutePath()).getParentFile();
            baseURL = parentFile.toURI().toURL().toExternalForm();
        } catch (Exception e) {
            baseURL = "";
        }
        fop.getUserAgent().setBaseURL(baseURL);
    }
    transform(src, stylesheet, fop);
    dest.close();
}
 
開發者ID:gildaslemoal,項目名稱:elpi,代碼行數:25,代碼來源:ApacheFopWorker.java

示例14: viewFO

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/**
 * Display an FO file in the AWT Preview.
 * @param fo the FO file
 * @throws IOException In case of an I/O problem
 * @throws FOPException In case of a problem during layout
 * @throws TransformerException In case of a problem during XML processing
 */
public void viewFO(File fo)
            throws IOException, FOPException, TransformerException {

    //Setup FOP
    Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW);

    try {

        //Load XSL-FO file (you can also do an XSL transformation here)
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        Source src = new StreamSource(fo);
        Result res = new SAXResult(fop.getDefaultHandler());
        transformer.transform(src, res);

    } catch (Exception e) {
        if (e instanceof FOPException) {
            throw (FOPException)e;
        }
        throw new FOPException(e);
    }
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:30,代碼來源:ExampleAWTViewer.java

示例15: render

import org.apache.fop.apps.Fop; //導入依賴的package包/類
/**
 * {@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);
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:21,代碼來源:FopPrintServlet.java


注:本文中的org.apache.fop.apps.Fop類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。