Examples of FopFactory


Examples of org.apache.fop.apps.FopFactory

     */
    public static Fop createFopInstance(OutputStream out, String outputFormat) throws FOPException {
        if (UtilValidate.isEmpty(outputFormat)) {
            outputFormat = MimeConstants.MIME_PDF;
        }
        FopFactory fopFactory = getFactoryInstance();
        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
        Fop fop;
        if (out != null) {
            fop = fopFactory.newFop(outputFormat, foUserAgent, out);
        } else {
            fop = fopFactory.newFop(outputFormat, foUserAgent);
        }
        return fop;
    }
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

     * @return  ByteArrayOutputStream containing the binary representation of a PDF document
     * @throws GeneralException
     */
    public static ByteArrayOutputStream render(Writer writer) throws GeneralException {

        FopFactory fopFactory = ApacheFopWorker.getFactoryInstance();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        TransformerFactory transFactory = TransformerFactory.newInstance();

        try {
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
            Transformer transformer = transFactory.newTransformer();

            // set the input source (XSL-FO) and generate the PDF
            Reader reader = new StringReader(writer.toString());
            Source src = new StreamSource(reader);

            // Get handler that is used in the generation process
            Result res = new SAXResult(fop.getDefaultHandler());

            try {
                // Transform the FOP XML source into a PDF, hopefully...
                transformer.transform(src, res);

                // We don't want to cache the images that get loaded by the FOP engine
                fopFactory.getImageFactory().clearCaches();

                return out;

            } catch (TransformerException e) {
                Debug.logError("FOP transform failed:" + e, module );
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

        String[] args = new String[] {"-enc", "ansi",
                ttfFile.getCanonicalPath(), metricsFile.getCanonicalPath()};
        TTFReader.main(args);
        assertTrue(metricsFile.isFile());
       
        FopFactory fopFactory = FopFactory.newInstance();
        FOUserAgent ua = fopFactory.newFOUserAgent();
        PDFRenderer renderer = new PDFRenderer();
        renderer.setUserAgent(ua);
        List fontList = new java.util.ArrayList();
        List triplets = new java.util.ArrayList();
        triplets.add(new FontTriplet(fontFamily, "normal", Font.WEIGHT_NORMAL));
        EmbedFontInfo font = new EmbedFontInfo(
                metricsFile.toURI().toASCIIString(),
                true, triplets,
                ttfFile.toURI().toASCIIString());
        fontList.add(font);
        renderer.addFontList(fontList);
       
        ua.setRendererOverride(renderer);
        OutputStream out = new NullOutputStream();
       
        Fop fop = fopFactory.newFop(null, ua, out);
       
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Source src = new StreamSource(new StringReader(
                "<root font-family='" + fontFamily + "'>Test!</root>"));
        Result res = new SAXResult(fop.getDefaultHandler());
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

    }

    public void testSVGNoViewbox() throws Exception {
        String uri = "test/resources/images/circles.svg";

        FopFactory ff = FopFactory.newInstance();
        ff.setSourceResolution(96);
        ff.setTargetResolution(300);

        FOUserAgent userAgent = ff.newFOUserAgent();

        ImageManager manager = ff.getImageManager();
        ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
        assertNotNull("ImageInfo must not be null", info);

        Image img = manager.getImage(info, ImageFlavor.XML_DOM,
                userAgent.getImageSessionContext());
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

            System.out.println("Output: PDF (" + pdffile + ")");
            System.out.println();
            System.out.println("Transforming...");

            // configure fopFactory as desired
            FopFactory fopFactory = FopFactory.newInstance();

            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
            // configure foUserAgent as desired

            // Setup output
            OutputStream out = new java.io.FileOutputStream(pdffile);
            out = new java.io.BufferedOutputStream(out);

            try {
                // Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

                // Setup XSLT
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

    @Override
    public void doExport(OutputStream out) throws IOException, JspException
    {
        String xmlResults = getXml();

        FopFactory fopFactory = FopFactory.newInstance();
        Source xslt = new StreamSource(getStyleSheet());
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer;
        try
        {
            transformer = factory.newTransformer(xslt);
        }
        catch (TransformerConfigurationException e)
        {
            throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$
        }

        boolean outputForDebug = log.isDebugEnabled();
        if (outputForDebug)
        {
            logXsl(xmlResults, transformer, null);
        }

        Fop fop;
        try
        {
            fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, out);
        }
        catch (FOPException e)
        {
            throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$
        }
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

     * @throws Exception if trouble
     */
    public static void transform(String xmlSrc, String styleSheetPath, File f) throws Exception
    {

        FopFactory fopFactory = FopFactory.newInstance();
        InputStream styleSheetStream = FopExportView.class.getResourceAsStream(styleSheetPath);

        Source xslt = new StreamSource(styleSheetStream);
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer;
        try
        {
            transformer = factory.newTransformer(xslt);
        }
        catch (TransformerConfigurationException e)
        {
            throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$
        }
        Fop fop;
        try
        {
            FileOutputStream fw = new FileOutputStream(f);
            fop = fopFactory.newFop(org.apache.xmlgraphics.util.MimeConstants.MIME_PDF, fw);
        }
        catch (FOPException e)
        {
            throw new JspException("Cannot configure pdf export " + e.getMessage(), e); //$NON-NLS-1$
        }
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

     * @return  ByteArrayOutputStream containing the binary representation of a PDF document
     * @throws GeneralException
     */
    public static ByteArrayOutputStream render(Writer writer) throws GeneralException {

        FopFactory fopFactory = ApacheFopWorker.getFactoryInstance();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        TransformerFactory transFactory = TransformerFactory.newInstance();

        try {
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
            Transformer transformer = transFactory.newTransformer();

            // set the input source (XSL-FO) and generate the PDF
            Reader reader = new StringReader(writer.toString());
            Source src = new StreamSource(reader);
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

     */
    public static Fop createFopInstance(OutputStream out, String outputFormat) throws FOPException {
        if (UtilValidate.isEmpty(outputFormat)) {
            outputFormat = MimeConstants.MIME_PDF;
        }
        FopFactory fopFactory = getFactoryInstance();
        FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
        Fop fop;
        if (out != null) {
            fop = fopFactory.newFop(outputFormat, foUserAgent, out);
        } else {
            fop = fopFactory.newFop(outputFormat, foUserAgent);
        }
        return fop;
    }
View Full Code Here

Examples of org.apache.fop.apps.FopFactory

     * @throws FOPException in case of an error during processing
     */
    public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
                throws FOPException {

        FopFactory factory = userAgent.getFactory();
        Fop fop;
        if (out != null) {
            fop = factory.newFop(outputFormat, userAgent, out);
        } else {
            fop = factory.newFop(outputFormat, userAgent);
        }

        // if base URL was not explicitly set in FOUserAgent, obtain here
        if (fop.getUserAgent().getBaseURL() == null) {
            String baseURL = null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.