Package org.apache.batik.transcoder

Examples of org.apache.batik.transcoder.Transcoder


     * Without special configuration stuff.
     * @throws Exception if a problem occurs
     */
    public void testGenericPDFTranscoder() throws Exception {
        //Create transcoder
        Transcoder transcoder = createTranscoder();
       
        //Setup input
        File svgFile = new File(getBaseDir(), "test/resources/fop/svg/text.svg");
        InputStream in = new java.io.FileInputStream(svgFile);
        try {
            TranscoderInput input = new TranscoderInput(in);
           
            //Setup output
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                TranscoderOutput output = new TranscoderOutput(out);
               
                //Do the transformation
                transcoder.transcode(input, output);
            } finally {
                out.close();
            }
            assertTrue("Some output expected", out.size() > 0);
        } finally {
View Full Code Here


        else{
            dstFiles = computeDstFiles(sources);
        }

        // Now, get the transcoder to use for the operation
        Transcoder transcoder = destinationType.getTranscoder();
        if(transcoder == null) {
            throw new SVGConverterException(ERROR_CANNOT_ACCESS_TRANSCODER,
                                             new Object[]{destinationType.toString()},
                                             true /* fatal error */);
        }

        // Now, compute the set of transcoding hints to use
        Map hints = computeTranscodingHints();
        transcoder.setTranscodingHints(hints);

        // Notify listener that task has been computed
        if(!controller.proceedWithComputedTask(transcoder,
                                               hints,
                                               sources,
View Full Code Here

        else{
            dstFiles = computeDstFiles(sources);
        }

        // Now, get the transcoder to use for the operation
        Transcoder transcoder = destinationType.getTranscoder();
        if(transcoder == null) {
            throw new SVGConverterException(ERROR_CANNOT_ACCESS_TRANSCODER,
                                             new Object[]{destinationType.toString()},
                                             true /* fatal error */);
        }

        // Now, compute the set of transcoding hints to use
        Map hints = computeTranscodingHints();
        transcoder.setTranscodingHints(hints);

        // Notify listener that task has been computed
        if(!controller.proceedWithComputedTask(transcoder,
                                               hints,
                                               sources,
View Full Code Here

        else{
            dstFiles = computeDstFiles(sources);
        }

        // Now, get the transcoder to use for the operation
        Transcoder transcoder = destinationType.getTranscoder();
        if(transcoder == null) {
            throw new SVGConverterException(ERROR_CANNOT_ACCESS_TRANSCODER,
                                             new Object[]{destinationType.toString()},
                                             true /* fatal error */);
        }

        // Now, compute the set of transcoding hints to use
        Map hints = computeTranscodingHints();
        transcoder.setTranscodingHints(hints);

        // Notify listener that task has been computed
        if(!controller.proceedWithComputedTask(transcoder,
                                               hints,
                                               sources,
View Full Code Here

                continue;
            }
        }
        TranscoderFactory factory =
            ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
        Transcoder t = factory.createTranscoder(mimeType);
        if (t == null) {
            error("No transcoder found for mime type : "+mimeType);
            System.exit(1);
        }
        for (Iterator iter = svgFiles.iterator(); iter.hasNext();) {
View Full Code Here

    }

    static void generateImages(String outputDirectory, String desc) {
        File destDir = new File(outputDirectory);
        File svgDir = new File(getSvgDirectory());
        Transcoder transcoder = getTranscoder();
        File [] samples = svgDir.listFiles();
        if (samples == null) {
            error("No SVG files has been found in "+
                  svgDir.getAbsolutePath());
            exit(2);
View Full Code Here

    }

    static void generateImages(String outputDirectory, String desc) {
        File destDir = new File(outputDirectory);
        File svgDir = new File(getSamplesDirectory());
        Transcoder transcoder = getTranscoder();
        File [] samples = svgDir.listFiles();
        if (samples == null) {
            error("No SVG files has been found in "+
                  svgDir.getAbsolutePath());
            exit(2);
View Full Code Here

            }
        }
        /*TranscoderFactory factory =
          ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
        */
        Transcoder t = null;
        if (mimeType.equals("image/jpg") ||
            mimeType.equals("image/jpeg") ||
            mimeType.equals("image/jpe")) {
            t = new JPEGTranscoder();
        } else if (mimeType.equals("image/png")) {
            t = new PNGTranscoder();
        } else if (mimeType.equals("application/pdf")) {
            try {
                Class cla = Class.forName("org.apache.fop.svg.PDFTranscoder");
                Object obj = cla.newInstance();
                t = (Transcoder)obj;
            } catch(Exception e) {
                t = null;
                error("PDF transcoder could not be loaded");
            }
        } else if (mimeType.equals("image/tiff")) {
            t = new TIFFTranscoder();
        }
        if (t == null) {
            error("No transcoder found for mime type : "+mimeType);
            System.exit(1);
        }

        if(!Float.isNaN(width)){
            t.addTranscodingHint(ImageTranscoder.KEY_WIDTH,
                                 new Float(width));
        }

        if(!Float.isNaN(height)){
            t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT,
                                 new Float(height));
        }

        t.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR,
                             background);

        for (Iterator iter = svgFiles.iterator(); iter.hasNext();) {
            String s = (String) iter.next();
            URL url = getSVGURL(s);
View Full Code Here

            }
        }
        /*TranscoderFactory factory =
          ConcreteTranscoderFactory.getTranscoderFactoryImplementation();
        */
        Transcoder t = null;
        if (mimeType.equals("image/jpg") ||
            mimeType.equals("image/jpeg") ||
            mimeType.equals("image/jpe")) {
            t = new JPEGTranscoder();
        } else if (mimeType.equals("image/png")) {
            t = new PNGTranscoder();
        } else if (mimeType.equals("application/pdf")) {
            try {
                Class cla = Class.forName("org.apache.fop.svg.PDFTranscoder");
                Object obj = cla.newInstance();
                t = (Transcoder)obj;
            } catch(Exception e) {
                t = null;
                error("PDF transcoder could not be loaded");
            }
        } else if (mimeType.equals("image/tiff")) {
            t = new TIFFTranscoder();
        }
        if (t == null) {
            error("No transcoder found for mime type : "+mimeType);
            System.exit(1);
        }

        if(!Float.isNaN(width)){
            t.addTranscodingHint(ImageTranscoder.KEY_WIDTH,
                                 new Float(width));
        }

        if(!Float.isNaN(height)){
            t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT,
                                 new Float(height));
        }

        for (Iterator iter = svgFiles.iterator(); iter.hasNext();) {
            String s = (String) iter.next();
View Full Code Here

     * @throws TranscoderException In case of a transcoding problem
     */
    public void convertSVG2PDF(File svg, File pdf) throws IOException, TranscoderException {

        //Create transcoder
        Transcoder transcoder = new PDFTranscoder();
        //Transcoder transcoder = new org.apache.fop.render.ps.PSTranscoder();

        //Setup input
        InputStream in = new java.io.FileInputStream(svg);
        try {
            TranscoderInput input = new TranscoderInput(in);

            //Setup output
            OutputStream out = new java.io.FileOutputStream(pdf);
            out = new java.io.BufferedOutputStream(out);
            try {
                TranscoderOutput output = new TranscoderOutput(out);

                //Do the transformation
                transcoder.transcode(input, output);
            } finally {
                out.close();
            }
        } finally {
            in.close();
View Full Code Here

TOP

Related Classes of org.apache.batik.transcoder.Transcoder

Copyright © 2018 www.massapicom. 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.