org.apache.batik.transcoder.TranscoderException Java Examples
The following examples show how to use
org.apache.batik.transcoder.TranscoderException.
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: SvgImageLoader.java From javafxsvg with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ImageFrame load(int imageIndex, int width, int height, boolean preserveAspectRatio, boolean smooth) throws IOException { if (0 != imageIndex) { return null; } Document document = createDocument(); Dimension fallbackDimension = (width <= 0 || height <= 0) ? dimensionProvider.getDimension(document) : null; float imageWidth = width > 0 ? width : (float) fallbackDimension.getWidth(); float imageHeight = height > 0 ? height : (float) fallbackDimension.getHeight(); try { return createImageFrame(document, imageWidth, imageHeight, getPixelScale()); } catch (TranscoderException ex) { throw new IOException(ex); } }
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: SvgImageLoader.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread public @Nullable ImageFrame load(int imageIndex, int width, int height, boolean preserveAspectRatio, boolean smooth) throws IOException { if (0 != imageIndex) { return null; } var imageWidth = width > 0 ? width : DEFAULT_SIZE; var imageHeight = height > 0 ? height : DEFAULT_SIZE; try { return createImageFrame(imageWidth, imageHeight, getPixelScale()); } catch (final TranscoderException ex) { throw new IOException(ex); } }
Example #10
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 #11
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 #12
Source File: BoundsExtractionTest.java From androidsvgdrawable-plugin with Apache License 2.0 | 6 votes |
@Test public void test() throws IOException, TranscoderException, InstantiationException, IllegalAccessException { // verify bounds QualifiedResource svg = qualifiedSVGResourceFactory.fromSVGFile(new File(PATH_IN + filename)); Rectangle svgBounds = svg.getBounds(); assertNotNull(svgBounds); assertEquals(ceil(expectedWidth), svgBounds.getWidth(), 0); assertEquals(ceil(expectedHeight), svgBounds.getHeight(), 0); Rectangle svgConstrainedBounds = svg.getScaledBounds(svg.getDensity().getValue()); assertNotNull(svgConstrainedBounds); assertEquals(ceil(constrainedWidth), svgConstrainedBounds.getWidth(), 0); assertEquals(ceil(constrainedHeight), svgConstrainedBounds.getHeight(), 0); // verify generated png (width, height) for each target density final String name = svg.getName(); for (Density.Value d : Density.Value.values()) { Reflect.on(svg).set("name", name + "_" + d.name()); plugin.transcode(svg, d, new File(PATH_OUT), null); BufferedImage image = ImageIO.read(new FileInputStream(new File(PATH_OUT, svg.getName() + "." + OUTPUT_FORMAT.name().toLowerCase()))); Rectangle expectedBounds = svg.getScaledBounds(d); assertEquals(expectedBounds.getWidth(), image.getWidth(), 0); assertEquals(expectedBounds.getHeight(), image.getHeight(), 0); } }
Example #13
Source File: SvgMaskTest.java From androidsvgdrawable-plugin with Apache License 2.0 | 6 votes |
@Test public void fromJson() throws TransformerException, ParserConfigurationException, SAXException, IOException, XPathExpressionException, InstantiationException, IllegalAccessException, TranscoderException { QualifiedResource maskResource = qualifiedSVGResourceFactory.fromSVGFile(new File(PATH_IN, mask)); SvgMask svgMask = new SvgMask(maskResource); Collection<QualifiedResource> maskedResources = svgMask.generatesMaskedResources(qualifiedSVGResourceFactory, dir, resources, useSameSvgOnlyOnceInMask, OverwriteMode.always); assertEquals(maskedResourcesNames.size(), maskedResources.size()); assertEquals(maskedResourcesNames.size(), dir.list().length); QualifiedResource qr; for (String maskedResource : maskedResourcesNames) { File masked = new File(dir, maskedResource); assertTrue(masked.getName() + " does not exists", masked.exists()); qr = qualifiedSVGResourceFactory.fromSVGFile(masked); assertTrue(qr.exists()); plugin.transcode(qr, mdpi, output, null); } }
Example #14
Source File: VisualConversionTest.java From androidsvgdrawable-plugin with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, TranscoderException, InstantiationException, IllegalAccessException { // verify bounds QualifiedResource svg = qualifiedSVGResourceFactory.fromSVGFile(new File(PATH_IN + filename + ".svg")); Rectangle rect = svg.getBounds(); Assert.assertNotNull(rect); plugin.transcode(svg, svg.getDensity().getValue(), new File(PATH_OUT), null); BufferedImage transcoded = ImageIO.read(new FileInputStream(new File(PATH_OUT, svg.getName() + ".png"))); BufferedImage original = ImageIO.read(new FileInputStream(new File(PATH_IN + svg.getName() + ".pngtest"))); assertEquals(0, bufferedImagesEqual(transcoded, original), 0.1); }
Example #15
Source File: DensityTypeTest.java From androidsvgdrawable-plugin with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, TranscoderException, InstantiationException, IllegalAccessException { // parsing Density d = Density.from(input); assertEquals(d.getClass(), c); assertEquals(d.getValue(), density); // scaling Rectangle inputBounds = new Rectangle(w, h); double ratio = d.ratio(inputBounds, ratioDensity); assertEquals(ratio, expectedRatio, 0); }
Example #16
Source File: NinePatchGenerationTest.java From androidsvgdrawable-plugin with Apache License 2.0 | 5 votes |
@Test public void fromJson() throws URISyntaxException, JsonIOException, JsonSyntaxException, IOException, TranscoderException, InstantiationException, IllegalAccessException { try (final Reader reader = new InputStreamReader(new FileInputStream(PATH_IN + ninePatchConfig))) { Type t = new TypeToken<Set<NinePatch>>() {}.getType(); Set<NinePatch> ninePatchSet = new GsonBuilder().create().fromJson(reader, t); NinePatchMap ninePatchMap = NinePatch.init(ninePatchSet); QualifiedResource svg = qualifiedSVGResourceFactory.fromSVGFile(new File(PATH_IN + resourceName)); NinePatch ninePatch = ninePatchMap.getBestMatch(svg); assertNotNull(ninePatch); final String name = svg.getName(); Reflect.on(svg).set("name", name + "_" + targetDensity.name()); plugin.transcode(svg, targetDensity, new File(PATH_OUT), ninePatch); final File ninePatchFile = new File(PATH_OUT, svg.getName() + ".9." + OUTPUT_FORMAT.name().toLowerCase()); final File nonNinePatchFile = new File(PATH_OUT, svg.getName() + "." + OUTPUT_FORMAT.name().toLowerCase()); if (OUTPUT_FORMAT.hasNinePatchSupport()) { assertTrue(FilenameUtils.getName(ninePatchFile.getAbsolutePath()) + " does not exists although the output format supports nine patch", ninePatchFile.exists()); assertTrue(FilenameUtils.getName(nonNinePatchFile.getAbsolutePath()) + " file does not exists although the output format supports nine patch", !nonNinePatchFile.exists()); BufferedImage image = ImageIO.read(new FileInputStream(ninePatchFile)); tester.test(image); // test corner pixels int w = image.getWidth(); int h = image.getHeight(); new PixelTester(new int[][] {}, new int[][] { {0, 0}, {0, h - 1}, {w - 1, 0}, {w - 1, h - 1} }).test(image); } else { assertTrue(FilenameUtils.getName(ninePatchFile.getAbsolutePath()) + " exists although the output format does not support nine patch", !ninePatchFile.exists()); assertTrue(FilenameUtils.getName(nonNinePatchFile.getAbsolutePath()) + " does not exists although the output format does not support nine patch", nonNinePatchFile.exists()); } } }
Example #17
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 #18
Source File: SvgImageLoader.java From javafxsvg with BSD 3-Clause "New" or "Revised" License | 5 votes |
private BufferedImage getTranscodedImage(Document document, float width, float height) throws TranscoderException { BufferedImageTranscoder trans = new BufferedImageTranscoder(BufferedImage.TYPE_INT_ARGB); trans.addTranscodingHint(KEY_WIDTH, width); trans.addTranscodingHint(KEY_HEIGHT, height); trans.transcode(new TranscoderInput(document), null); return trans.getBufferedImage(); }
Example #19
Source File: SvgImageLoader.java From javafxsvg with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ImageFrame createImageFrame(Document document, float width, float height, float pixelScale) throws TranscoderException { BufferedImage bufferedImage = getTranscodedImage(document, width * pixelScale, height * pixelScale); ByteBuffer imageData = getImageData(bufferedImage); return new FixedPixelDensityImageFrame(ImageStorage.ImageType.RGBA, imageData, bufferedImage.getWidth(), bufferedImage.getHeight(), getStride(bufferedImage), null, pixelScale, null); }
Example #20
Source File: PDVCLIMainClass.java From PDV with GNU General Public License v3.0 | 5 votes |
/** * Export spectra * @param graphicsPanel Spectrum and fragment panel * @param finalSelectedFile pic file path */ private void exportFigure(Component graphicsPanel, String finalSelectedFile){ try { Export.exportPic(graphicsPanel, graphicsPanel.getBounds(), new File(finalSelectedFile), imageType); } catch (IOException | TranscoderException e) { e.printStackTrace(); } }
Example #21
Source File: SVGIcon.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Generate the BufferedImage. */ protected void generateBufferedImage(TranscoderInput in, int w, int h) throws TranscoderException { BufferedImageTranscoder t = new BufferedImageTranscoder(); if (w != 0 && h != 0) { t.setDimensions(w, h); } t.transcode(in, null); bufferedImage = t.getBufferedImage(); width = bufferedImage.getWidth(); height = bufferedImage.getHeight(); }
Example #22
Source File: SvgImageLoader.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@FxThread private @NotNull BufferedImage getTranscodedImage(float width, float height) throws TranscoderException { var trans = new BufferedImageTranscoder(BufferedImage.TYPE_INT_ARGB); trans.addTranscodingHint(KEY_WIDTH, width); trans.addTranscodingHint(KEY_HEIGHT, height); trans.transcode(new TranscoderInput(this.input), null); return trans.getBufferedImage(); }
Example #23
Source File: RealTimeExportJDialog.java From PDV with GNU General Public License v3.0 | 5 votes |
/** * Export single pic * @param outputPathName File name */ private void exportFigure(String outputPathName){ File imageFile = new File(outputPathName); try { Export.exportPic(spectrumSplitPane, spectrumSplitPane.getBounds(), imageFile, imageType); } catch (IOException | TranscoderException e) { e.printStackTrace(); } }
Example #24
Source File: PDVCLIMainClass.java From PDV with GNU General Public License v3.0 | 5 votes |
/** * Export chart * @param chart chart * @param finalSelectedFile pic file path */ private void exportFigure(JFreeChart chart, String finalSelectedFile){ try { Export.exportPic(chart, spectrumSplitPane.getBounds(), new File(finalSelectedFile), imageType); } catch (IOException | TranscoderException e) { e.printStackTrace(); } }
Example #25
Source File: SVGHelper.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** * Loads SVG file as an {@link Image}. The resolution of the generated image is determined by the * width and height parameters. Consequently scaling to a much larger size will result in "pixelation". * Client code is hence advised to reload the SVG resource using the new width and height when * the container widget is resized. * * @param fileStream Non-null input stream to SVG file. * @param width The wanted width of the image. * @param height The wanted height of the image. * @return A {@link Image} object if the input stream can be parsed and transcoded. */ public static Image loadSVG(InputStream fileStream, double width, double height) throws Exception{ BufferedImageTranscoder bufferedImageTranscoder = new BufferedImageTranscoder(); TranscoderInput input = new TranscoderInput(fileStream); try{ bufferedImageTranscoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, (float)width); bufferedImageTranscoder.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, (float)height); bufferedImageTranscoder.transcode(input, null); return SwingFXUtils.toFXImage(bufferedImageTranscoder.getBufferedImage(), null); } catch (TranscoderException e) { throw new Exception("Unable to transcode SVG file", e); } }
Example #26
Source File: AngrySquiggleGenerator.java From MSPaintIDE with MIT License | 5 votes |
public AngrySquiggleGenerator(int fontSize) throws TranscoderException { double squiggleHeight = fontSize / 3D; squiggleHeight /= 4; squiggleHeight = 6 * (Math.round(squiggleHeight / 6)); AngrySquiggleTranscoder transcoder = new AngrySquiggleTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) (int) Math.floor(squiggleHeight)); TranscoderInput input = new TranscoderInput(getClass().getClassLoader().getResourceAsStream("angry_squiggle.svg")); transcoder.transcode(input, new AngrySquiggleTranscoderOutput()); this.generatedPNG = transcoder.getImage(); LOGGER.info("Generated angry squiggle from SVG. Dimensions: " + this.generatedPNG.getWidth() + " x " + this.generatedPNG.getHeight()); }
Example #27
Source File: SvgImageLoader.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@FxThread private @NotNull ImageFrame createImageFrame(int width, int height, float pixelScale) throws TranscoderException { var bufferedImage = getTranscodedImage(width * pixelScale, height * pixelScale); var imageData = getImageData(bufferedImage); return new FixedPixelDensityImageFrame(ImageType.RGBA, imageData, bufferedImage.getWidth(), bufferedImage.getHeight(), getStride(bufferedImage), null, pixelScale, null); }
Example #28
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 #29
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 #30
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(); }