@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(); }
transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, w); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, h); transcoder.transcode(new TranscoderInput(in), new TranscoderOutput(out));
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import org.apache.batik.transcoder.Transcoder; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.fop.svg.PDFTranscoder; public class Test { public static void main(String[] argv) throws TranscoderException, FileNotFoundException { Transcoder transcoder = new PDFTranscoder(); TranscoderInput transcoderInput = new TranscoderInput(new FileInputStream(new File("/tmp/test.svg"))); TranscoderOutput transcoderOutput = new TranscoderOutput(new FileOutputStream(new File("/tmp/test.pdf"))); transcoder.transcode(transcoderInput, transcoderOutput); } }
private synchronized void init() throws IOException { // Need the extra test, to avoid throwing an IOException from the Transcoder if (imageInput == null) { throw new IllegalStateException("input == null"); } if (reader == null) { WMFTranscoder transcoder = new WMFTranscoder(); ByteArrayOutputStream output = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(output, "UTF8"); try { TranscoderInput in = new TranscoderInput(IIOUtil.createStreamAdapter(imageInput)); TranscoderOutput out = new TranscoderOutput(writer); // TODO: Transcodinghints? transcoder.transcode(in, out); } catch (TranscoderException e) { throw new IIOException(e.getMessage(), e); } reader = new SVGImageReader(getOriginatingProvider()); reader.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(output.toByteArray()))); } }
TranscoderOutput output = new TranscoderOutput(outStream);
private void rasterizeToFile(String content, File out, int width, int height) throws IOException { if (out.exists()) { this.logger.debug("Reusing existing temporary raster image: {}", out.getAbsolutePath()); return; } try (OutputStream fout = new FileOutputStream(out)) { this.logger.debug("Rasterizing to temp file: {}", out.getAbsolutePath()); TranscoderInput input = new TranscoderInput(new StringReader(content)); TranscoderOutput output = new TranscoderOutput(fout); rasterize(input, output, width, height); } }
private void rasterizeToFile(String content, File out, int width, int height) throws IOException { if (out.exists()) { this.logger.debug("Reusing existing temporary raster image: {}", out.getAbsolutePath()); return; } try (OutputStream fout = new FileOutputStream(out)) { this.logger.debug("Rasterizing to temp file: {}", out.getAbsolutePath()); TranscoderInput input = new TranscoderInput(new StringReader(content)); TranscoderOutput output = new TranscoderOutput(fout); rasterize(input, output, width, height); } }
private static ByteArrayOutputStream saveAsBytes(ImageTranscoder t, Document doc) throws Exception { TranscoderInput input = new TranscoderInput(doc); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outputStream); t.transcode(input, output); outputStream.flush(); return outputStream; }
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream(new FileOutputStream(f)); trans.writeImage(img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) { } statusBar.setMessage (resources.getString("Message.done")); } }.start();
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream(new FileOutputStream(f)); trans.writeImage(img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) { } statusBar.setMessage (resources.getString("Message.done")); } }.start();
private byte[] pngBytesFromSvg(String svg) throws TranscoderException { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final TranscoderInput input = new TranscoderInput(new StringReader(svg)); final TranscoderOutput output = new TranscoderOutput(outputStream); final PNGTranscoder converter = new PNGTranscoder(); converter.transcode(input, output); byte[] bytes = outputStream.toByteArray(); try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } return bytes; }
/** * Helper method: creates a valid reference image */ public static URL createValidReferenceImage(String svgContent) throws Exception{ TranscoderInput validSrc = new TranscoderInput(new StringReader(svgContent)); File tmpFile = File.createTempFile(SVGRenderingAccuracyTest.TEMP_FILE_PREFIX, SVGRenderingAccuracyTest.TEMP_FILE_SUFFIX); TranscoderOutput validDst = new TranscoderOutput(new FileOutputStream(tmpFile)); ImageTranscoder transcoder = new PNGTranscoder(); transcoder.transcode(validSrc, validDst); tmpFile.deleteOnExit(); return tmpFile.toURI().toURL(); }
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream (new FileOutputStream(f)); trans.writeImage (img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) {} statusBar.setMessage (resources.getString("Message.done")); } }.start();
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream(new FileOutputStream(f)); trans.writeImage(img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) {} statusBar.setMessage (resources.getString("Message.done")); } }.start();
private void convertSvgToPng(File svg, File png) throws Exception { String svgUriInput = svg.toURI().toURL().toString(); TranscoderInput inputSvgImage = new TranscoderInput(svgUriInput); //Step-2: Define OutputStream to PNG Image and attach to TranscoderOutput OutputStream pngOStream = new FileOutputStream(png); TranscoderOutput outputPngImage = new TranscoderOutput(pngOStream); // Step-3: Create PNGTranscoder and define hints if required PNGTranscoder myConverter = new PNGTranscoder(); // Step-4: Convert and Write output myConverter.transcode(inputSvgImage, outputPngImage); // Step 5- close / flush Output Stream pngOStream.flush(); pngOStream.close(); } public String replaceSvgWithPng(File htmlFile) throws Exception {
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream (new FileOutputStream(f)); trans.writeImage (img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) {} statusBar.setMessage (resources.getString("Message.done")); } }.start();
public void run() { try { currentSavePath = f; OutputStream ostream = new BufferedOutputStream(new FileOutputStream(f)); trans.writeImage(img, new TranscoderOutput(ostream)); ostream.close(); } catch (Exception ex) {} statusBar.setMessage (resources.getString("Message.done")); } }.start();
private void transcodeAndTag(final Avatar avatar, final Avatar.Size size, final File transcoded) throws IOException { try (final OutputStream outputStream = new FileOutputStream(transcoded); final InputStream svgFileStream = AvatarManagerImpl.class.getResourceAsStream("/avatars/" + avatar.getFileName())) { final TranscoderInput transcoderInput = new TranscoderInput(svgFileStream); final TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream); final PNGTranscoder transcoder = newPNGTranscoder(size); transcoder.transcode(transcoderInput, transcoderOutput); avatarTagger.tagSingleAvatarFile(transcoded, transcoded); } catch (TranscoderException e) { throw new RuntimeException(e); } }
/** * Returns the image that represents the SVG document as a JPEG. * * @param outputStream The stream to use. */ public void createJPEG(OutputStream outputStream) throws TranscoderException { // Create a JPEG transcoder JPEGTranscoder t = new JPEGTranscoder(); // Set the transcoding hints. t.setTranscodingHints((Map)hints); // Set up the output stream TranscoderOutput output = new TranscoderOutput(outputStream); // Save the image. t.transcode(input, output); }
public static void svg2pdf(List<String> svg, OutputStream out) throws Exception { TranscoderOutput output = new TranscoderOutput(out); PDFPrinter transcoder = new PDFPrinter(svg); transcoder.addTranscodingHint(KEY_WIDTH, 800f); transcoder.addTranscodingHint(KEY_HEIGHT, 1200f); transcoder.addTranscodingHint(KEY_AUTO_FONTS, true); final int dpi = 300; transcoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, 25.4f / dpi); transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE); transcoder.addTranscodingHint(PDFTranscoder.KEY_STROKE_TEXT, Boolean.FALSE); transcoder.transcode(output); }