org.apache.batik.transcoder.TranscoderOutput Java Examples
The following examples show how to use
org.apache.batik.transcoder.TranscoderOutput.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExportHighCharts.java From Knowage-Server with GNU Affero General Public License v3.0 | 9 votes |
public static void transformSVGIntoPNG(InputStream inputStream, OutputStream outputStream) { // create a PNG transcoder PNGTranscoder t = new PNGTranscoder(); // set the transcoding hints t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(1000)); t.addTranscodingHint(PNGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*"); t.addTranscodingHint(PNGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true)); t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(true)); t.addTranscodingHint(PNGTranscoder.KEY_DEFAULT_FONT_FAMILY, "Arial"); // create the transcoder input Reader reader = new InputStreamReader(inputStream); TranscoderInput input = new TranscoderInput(reader); // save the image try { // create the transcoder output TranscoderOutput output = new TranscoderOutput(outputStream); t.transcode(input, output); } catch (TranscoderException e) { logger.error("Impossible to convert svg to png: " + e.getCause(), e); throw new SpagoBIEngineRuntimeException("Impossible to convert svg to png: " + e.getCause(), e); } }
Example #2
Source File: SimpleImageTranscoder.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override protected void transcode(final Document document, final String uri, final TranscoderOutput output) throws TranscoderException { super.transcode(document, uri, output); final int w = (int) (width + 0.5); final int h = (int) (height + 0.5); final ImageRenderer renderer = createImageRenderer(); renderer.updateOffScreen(w, h); // curTxf.translate(0.5, 0.5); renderer.setTransform(curTxf); renderer.setTree(root); root = null; // We're done with it... try { final Shape raoi = new Rectangle2D.Float(0, 0, width, height); // Warning: the renderer's AOI must be in user space renderer.repaint(curTxf.createInverse().createTransformedShape(raoi)); image = renderer.getOffScreen(); } catch (final Exception ex) { throw new TranscoderException(ex); } }
Example #3
Source File: PDFRendererImpl.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Transcode a SVG format Reader and write it to an output stream as a PDF image. * * @param dom the svg document object model * @param ostream the output stream * * @throws TranscoderException */ protected void transcode2PDF(Reader r, OutputStream ostream) throws TranscoderException { // transcode the data TranscoderInput tcin = new TranscoderInput(r); TranscoderOutput tcout = new TranscoderOutput(ostream); transcode2PDF(tcin, tcout); // flush the output stream try { ostream.flush(); } catch (IOException ioe) { // ignore output stream flush error } }
Example #4
Source File: PDFRendererImpl.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Transcode a SVG format Reader and write it to an output stream as a PDF image. * * @param dom the svg document object model * @param ostream the output stream * * @throws TranscoderException */ protected void transcode2PDF(Document dom, OutputStream ostream) throws TranscoderException { // transcode the data TranscoderInput tcin = new TranscoderInput(dom); TranscoderOutput tcout = new TranscoderOutput(ostream); transcode2PDF(tcin, tcout); // flush the output stream try { ostream.flush(); } catch (IOException ioe) { // ignore output stream flush error } }
Example #5
Source File: ExportHighCharts.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
public static void transformSVGIntoJPEG(InputStream inputStream, OutputStream outputStream) { // create a JPEG transcoder JPEGTranscoder t = new JPEGTranscoder(); // set the transcoding hints t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1)); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000)); t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*"); t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true)); t.addTranscodingHint(JPEGTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(true)); // create the transcoder input Reader reader = new InputStreamReader(inputStream); TranscoderInput input = new TranscoderInput(reader); // create the transcoder output TranscoderOutput output = new TranscoderOutput(outputStream); // save the image try { t.transcode(input, output); } catch (TranscoderException e) { logger.error("Impossible to convert svg to jpeg: " + e.getCause(), e); throw new SpagoBIEngineRuntimeException("Impossible to convert svg to jpeg: " + e.getCause(), e); } }
Example #6
Source File: SVGMapConverter.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
/** * Transform the svg file into a jpeg image. * * @param inputStream * the strema of the svg map * @param outputStream * the output stream where the jpeg image is written * * @throws Exception * raised if some errors occur during the elaboration */ public static void SVGToJPEGTransform(InputStream inputStream, OutputStream outputStream) throws IOException { // create a JPEG transcoder JPEGTranscoder t = new JPEGTranscoder(); // set the transcoding hints t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1)); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000)); t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*"); t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true)); t.addTranscodingHint(JPEGTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(true)); // create the transcoder input Reader reader = new InputStreamReader(inputStream); TranscoderInput input = new TranscoderInput(reader); // create the transcoder output TranscoderOutput output = new TranscoderOutput(outputStream); // save the image try { t.transcode(input, output); } catch (TranscoderException e) { throw new IOException("Impossible to convert svg to jpeg: " + e.getCause()); } }
Example #7
Source File: ImageImpl.java From tephra with MIT License | 6 votes |
@Override public boolean svg2png(String svg, int width, int height, OutputStream outputStream) { try (Reader reader = new StringReader(svg)) { PNGTranscoder pngTranscoder = new PNGTranscoder(); pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, 1.0F * width); pngTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, 1.0F * height); pngTranscoder.transcode(new TranscoderInput(reader), new TranscoderOutput(outputStream)); outputStream.flush(); return true; } catch (Throwable throwable) { logger.warn(throwable, "转换SVG文档[{}:{}:{}]为PNG图片时发生异常!", svg, width, height); return false; } }
Example #8
Source File: DownloadCloudServlet.java From swcv with MIT License | 6 votes |
private byte[] convertToPDF(WordCloud cloud) throws TranscoderException, IOException { // Create a JPEG transcoder PDFTranscoder t = new PDFTranscoder(); // Set the transcoding hints t.addTranscodingHint(PDFTranscoder.KEY_WIDTH, new Float(cloud.getWidth() + 20)); t.addTranscodingHint(PDFTranscoder.KEY_HEIGHT, new Float(cloud.getHeight() + 20)); // Create the transcoder input InputStream is = new ByteArrayInputStream(cloud.getSvg().getBytes()); TranscoderInput input = new TranscoderInput(is); // Create the transcoder output ByteArrayOutputStream ostream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(ostream); // Save the image t.transcode(input, output); // Flush and close the stream ostream.flush(); ostream.close(); return ostream.toByteArray(); }
Example #9
Source File: DownloadCloudServlet.java From swcv with MIT License | 6 votes |
private byte[] convertToPNG(WordCloud cloud) throws TranscoderException, IOException { // Create a PNG transcoder PNGTranscoder t = new PNGTranscoder(); // Set the transcoding hints t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(cloud.getWidth() + 20)); t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(cloud.getHeight() + 20)); // Create the transcoder input InputStream is = new ByteArrayInputStream(cloud.getSvg().getBytes()); TranscoderInput input = new TranscoderInput(is); // Create the transcoder output ByteArrayOutputStream ostream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(ostream); // Save the image t.transcode(input, output); // Flush and close the stream ostream.flush(); ostream.close(); return ostream.toByteArray(); }
Example #10
Source File: BatikImageRenderer.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
private static byte[] getPDFByteArray(final Document document, final int width) { // Create a pdf transcoder final PDFTranscoder t = new PDFTranscoder(); t.addTranscodingHint(PDFTranscoder.KEY_AUTO_FONTS, false); t.addTranscodingHint(PDFTranscoder.KEY_WIDTH, new Float(width)); TranscoderInput input = new TranscoderInput(document); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final TranscoderOutput output = new TranscoderOutput(baos); // Save the image. try { t.transcode(input, output); } catch (TranscoderException ex) { log.fatal("Exception encountered " + ex, ex); } return baos.toByteArray(); }
Example #11
Source File: SvgFile.java From birt with Eclipse Public License 1.0 | 5 votes |
public static byte[] transSvgToArray( InputStream inputStream ) throws Exception { PNGTranscoder transcoder = new PNGTranscoder( ); // create the transcoder input TranscoderInput input = new TranscoderInput( inputStream ); // create the transcoder output ByteArrayOutputStream ostream = new ByteArrayOutputStream( ); TranscoderOutput output = new TranscoderOutput( ostream ); transcoder.transcode( input, output ); // flush the stream ostream.flush( ); // use the output stream as Image input stream. return ostream.toByteArray( ); }
Example #12
Source File: RenderUtils.java From swcv with MIT License | 5 votes |
public static byte[] createVector(WordCloudRenderer renderer, SVGAbstractTranscoder transcoder) { byte[] svg = createSVG(renderer); // Set the transcoding hints transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new Float(renderer.getActualWidth() + 20)); transcoder.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new Float(renderer.getActualHeight() + 20)); // Create the transcoder input InputStream is = new ByteArrayInputStream(svg); TranscoderInput input = new TranscoderInput(is); // Create the transcoder output ByteArrayOutputStream ostream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(ostream); try { // Save the image transcoder.transcode(input, output); // Flush and close the stream ostream.flush(); ostream.close(); } catch (Exception e) { throw new RuntimeException(e); } return ostream.toByteArray(); }
Example #13
Source File: ModelSaveRestResource.java From opscenter with Apache License 2.0 | 5 votes |
@RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT) @ResponseStatus(value = HttpStatus.OK) public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) { try { Model model = repositoryService.getModel(modelId); ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.getFirst("name")); modelJson.put(MODEL_DESCRIPTION, values.getFirst("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.getFirst("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); } catch (Exception e) { LOGGER.error("Error saving model", e); throw new ActivitiException("Error saving model", e); } }
Example #14
Source File: SimpleImageTranscoder.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private BufferedImage createImage() { if (document == null) { return null; } try { if (canvasWidth >= 0) { addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(canvasWidth)); } else { removeTranscodingHint(ImageTranscoder.KEY_WIDTH); } if (canvasHeight >= 0) { addTranscodingHint(ImageTranscoder.KEY_HEIGHT, new Float(canvasHeight)); } else { removeTranscodingHint(ImageTranscoder.KEY_HEIGHT); } if (canvasAOI != null) { addTranscodingHint(ImageTranscoder.KEY_AOI, canvasAOI); } else { removeTranscodingHint(ImageTranscoder.KEY_AOI); } BufferedImage imageToReturn; transcode(new TranscoderInput(document), new TranscoderOutput()); imageToReturn = image; image = null; return imageToReturn; } catch (final TranscoderException e) { Activator.logError("Error transcoding SVG image", e); } return null; }
Example #15
Source File: BatikUtils.java From workcraft with MIT License | 5 votes |
public static void transcode(VisualModel model, OutputStream out, Transcoder transcoder) throws SerialisationException { ByteArrayOutputStream bufOut = new ByteArrayOutputStream(); BatikUtils.generateSvgGraphics(model, bufOut); ByteArrayInputStream bufIn = new ByteArrayInputStream(bufOut.toByteArray()); TranscoderInput transcoderInput = new TranscoderInput(bufIn); TranscoderOutput transcoderOutput = new TranscoderOutput(out); try { transcoder.transcode(transcoderInput, transcoderOutput); } catch (TranscoderException e) { throw new SerialisationException(e); } }
Example #16
Source File: FlowableModelManagerController.java From hsweb-framework with Apache License 2.0 | 5 votes |
@PutMapping(value = "/{modelId}") @ResponseStatus(value = HttpStatus.OK) @Authorize(action = Permission.ACTION_UPDATE) public void saveModel(@PathVariable String modelId, @RequestParam Map<String, String> values) throws TranscoderException, IOException { Model model = repositoryService.getModel(modelId); JSONObject modelJson = JSON.parseObject(model.getMetaInfo()); modelJson.put(MODEL_NAME, values.get("name")); modelJson.put(MODEL_DESCRIPTION, values.get("description")); model.setMetaInfo(modelJson.toString()); model.setName(values.get("name")); repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); // Setup output ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); // Do the transformation transcoder.transcode(input, output); final byte[] result = outStream.toByteArray(); repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); }
Example #17
Source File: AbstractSvgTest.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void export(JasperPrint print, OutputStream out) throws JRException, IOException { DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); Document document = domImpl.createDocument(null, "svg", null); SVGGraphics2D grx = new SVGGraphics2D( SVGGeneratorContext.createDefault(document), false // this is for textAsShapes, but does not seem to have effect in our case ); JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setExporterInput(new SimpleExporterInput(print)); SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput(); Graphics2D g = (Graphics2D)grx.create(); output.setGraphics2D(g); exporter.setExporterOutput(output); for (int pageIndex = 0; pageIndex < print.getPages().size(); pageIndex++) { g.translate(0, pageIndex * print.getPageHeight()); SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration(); configuration.setPageIndex(pageIndex); exporter.setConfiguration(configuration); exporter.exportReport(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); // use OutputStreamWriter instead of StringWriter so that we have "encoding" attribute in <xml> header tag. grx.stream(new OutputStreamWriter(baos, "UTF-8"), true); SVGTranscoder transcoder = new SVGTranscoder(); transcoder.addTranscodingHint(SVGTranscoder.KEY_NEWLINE, SVGTranscoder.VALUE_NEWLINE_LF); try { transcoder.transcode( new TranscoderInput(new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()), "UTF-8")), new TranscoderOutput(new OutputStreamWriter(out, "UTF-8")) ); } catch (TranscoderException e) { throw new JRException(e); } out.close(); }
Example #18
Source File: BufferedImageTranscoder.java From javafxsvg with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void writeImage(BufferedImage img, TranscoderOutput to) throws TranscoderException { this.img = img; }
Example #19
Source File: AngrySquiggleTranscoder.java From MSPaintIDE with MIT License | 4 votes |
@Override public void writeImage(BufferedImage image, TranscoderOutput output) throws TranscoderException { super.writeImage(image, output); this.image = image; }
Example #20
Source File: SVGHelper.java From phoebus with Eclipse Public License 1.0 | 4 votes |
@Override public void writeImage(BufferedImage bufferedImage, TranscoderOutput transcoderOutput) { this.bufferedImage = bufferedImage; }
Example #21
Source File: IconUtil.java From idea-php-typo3-plugin with MIT License | 4 votes |
public void writeImage(BufferedImage img, TranscoderOutput out) { }
Example #22
Source File: ImageOutputBaseTest.java From birt with Eclipse Public License 1.0 | 4 votes |
public void runTest( ) throws Throwable { Map<ImageCompParam, Integer> params = new HashMap<ImageCompParam, Integer>(); params.put(ImageCompParam.TOLERANCE, 4); // 1: verify PNG Png24PrimitiveGen generator2 = new Png24PrimitiveGen(new FileInputStream(workspaceDir+File.separator+ImageRenderTest.INDIR+dirName+File.separator+filename+ImageRenderTest.DRAWEXT), workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".png");//$NON-NLS-1$ generator2.generate(); generator2.flush(); Image result = ImageUtil.compare( workspaceDir+File.separator+ImageRenderTest.CONTROLDIR+dirName+File.separator+filename+".png", //$NON-NLS-1$ workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".png", params); //$NON-NLS-1$ if(result != null) { ImageUtil.savePNG(result, workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".diff.png"); fail(); } // 2: verify SVG SvgPrimitiveGen generator3 = new SvgPrimitiveGen(new FileInputStream(workspaceDir+File.separator+ImageRenderTest.INDIR+dirName+File.separator+filename+ImageRenderTest.DRAWEXT), workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".svg"); //$NON-NLS-1$ generator3.generate(); generator3.flush(); // convert golden and actual SVG to PNG String[] files = { workspaceDir+File.separator+ImageRenderTest.CONTROLDIR+dirName+File.separator+filename+".svg", //$NON-NLS-1$ workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".svg" //$NON-NLS-1$ }; for(String file: files) { InputStream inStream = new FileInputStream(file); TranscoderInput input = new TranscoderInput( inStream ); OutputStream outStream = new FileOutputStream(file + ".png"); //$NON-NLS-1$ TranscoderOutput output = new TranscoderOutput(outStream); PNGTranscoder converter = new PNGTranscoder(); converter.transcode(input, output); outStream.flush(); outStream.close(); } result = ImageUtil.compare( files[0] + ".png", //$NON-NLS-1$ files[1] + ".png"); //$NON-NLS-1$ if(result != null) { ImageUtil.savePNG(result, files[1] + ".diff.png"); //$NON-NLS-1$ fail(); } // PdfPrimitiveGen generator4 = new PdfPrimitiveGen(new FileInputStream(workspaceDir+File.separator+ImageRenderTest.INDIR+dirName+File.separator+filename+ImageRenderTest.DRAWEXT), workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".pdf");//$NON-NLS-1$ // generator4.generate(); // generator4.flush(); // assertTrue(FileUtil.compareFiles(new FileInputStream(workspaceDir+File.separator+ImageRenderTest.OUTDIR+dirName+File.separator+filename+".pdf"), new FileInputStream(workspaceDir+File.separator+ImageRenderTest.CONTROLDIR+dirName+File.separator+filename+".pdf")));//$NON-NLS-1$//$NON-NLS-2$ }
Example #23
Source File: SvgConversionController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 3 votes |
private void convertToPdf( String svg, OutputStream out ) throws TranscoderException { svg = replaceUnsafeSvgText( svg ); PDFTranscoder transcoder = new PDFTranscoder(); TranscoderInput input = new TranscoderInput( new StringReader( svg ) ); TranscoderOutput output = new TranscoderOutput( out ); transcoder.transcode( input, output ); }
Example #24
Source File: SvgConversionController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 3 votes |
private void convertToPng( String svg, OutputStream out ) throws TranscoderException { svg = replaceUnsafeSvgText( svg ); PNGTranscoder transcoder = new PNGTranscoder(); transcoder.addTranscodingHint( ImageTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE ); TranscoderInput input = new TranscoderInput( new StringReader( svg ) ); TranscoderOutput output = new TranscoderOutput( out ); transcoder.transcode( input, output ); }
Example #25
Source File: SVGIcon.java From mars-sim with GNU General Public License v3.0 | 2 votes |
/** * Writes the specified image to the specified output. * @param img the image to write * @param output the output where to store the image * @param TranscoderException if an error occured while storing the image */ public void writeImage(BufferedImage img, TranscoderOutput output) throws TranscoderException { bufferedImage = img; }
Example #26
Source File: SvgBatikIcon.java From radiance with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Writes the specified image to the specified output. * * @param img the image to write * @param output the output where to store the image */ @Override public void writeImage(BufferedImage img, TranscoderOutput output) { bufferedImage = img; }