You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by keerthigswe <ke...@gmail.com> on 2012/02/01 10:57:28 UTC

WMF to SVG Conversion.

Hi all,
I am trying to convert the WMF images found in a word document to JPEG. To
do that, am converting the WMF image to SVG first, then to JPEG. On
conversion, the special characters in the WMF files are not converted
properly. I guess that there is something to do with the encoding style
while reading/writing the file. The following is the piece of code i have
written to convert the image and have attached the image files too.
Appreciate ur help.

public static void main(String[] a) throws Exception {
	String wmfPath = "D:\\GK\\test\\image1.wmf";
	File wmf = new File(wmfPath);
	FileInputStream wmfStream = new FileInputStream(wmf);
	ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
	int noOfByteRead = 0;
	while ((noOfByteRead = wmfStream.read()) != -1) {
		imageOut.write(noOfByteRead);
	}
	imageOut.flush();

	WMFTranscoder transcoder = new WMFTranscoder();
	TranscodingHints hints = new TranscodingHints();
	WMFHeaderProperties properties = new WMFHeaderProperties(wmf);
	hints.put(WMFTranscoder.KEY_HEIGHT, (float) properties.getHeightUnits());
	hints.put(WMFTranscoder.KEY_WIDTH, (float) properties.getWidthUnits());
	transcoder.setTranscodingHints(hints);
	
	TranscoderInput input = new TranscoderInput(new
ByteArrayInputStream(imageOut.toByteArray()));

	String svgFile = wmfPath.replace("wmf", "svg");
	FileOutputStream fos = new FileOutputStream(svgFile);
            TranscoderOutput svg = new TranscoderOutput(new
OutputStreamWriter(fos, "UTF-8"));

       
	transcoder.transcode(input, svg);
		
	TranscoderInput svgInput = new TranscoderInput(new
File(svgFile).toURL().toString());
	String jpgFile = wmfPath.replace("wmf", "jpg");
	OutputStream ostream = new FileOutputStream(jpgFile);
	TranscoderOutput jpegOutput = new TranscoderOutput(ostream);
	ImageTranscoder t = new JPEGTranscoder();
	t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
	t.transcode(svgInput, jpegOutput);
	ostream.flush();
	ostream.close();
}
 

Thanks in advance.

http://batik.2283329.n4.nabble.com/file/n4347364/image1.wmf image1.wmf 
http://batik.2283329.n4.nabble.com/file/n4347364/image1.jpg image1.jpg 

--
View this message in context: http://batik.2283329.n4.nabble.com/WMF-to-SVG-Conversion-tp4347364p4347364.html
Sent from the Batik - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org