Need to convert EMF to jpeg,png file formats using java
I need to convert the emf,wmf file formats to png or jpeg using full java code(since these formats are not supported in some browsers)..Can anybody guide me..
Thanks in advanc开发者_Python百科e
The fastest way is probably to use Imagemagick. It does support the EMF and WMF formats. I have used successfully Imagemagick from Java using im4java, an Java interface for Imagemagick.
Alternatively you can look at Jmagick, another Java interface for Imagemagick. I have found this one more complex to use.
Other options: FreeHEP and Apache Batik. I haven't tried them, though.
Fast investigation showed the following command line utility: http://www.verypdf.com/htmltools/html-converter/emf-to-bmp.html
You can run it from java program. Unfortunately I have not seen pure java solution. Will be happy to know if one exists.
A pure-java solution is TwelveMonkeys with Batik supports reading WMF file.
Batik can handle only old WMF with Aldus Placable Header, unable parsing for some other types (recently in MS Office metadata). See WMF formats: http://wvware.sourceforge.net/caolan/ora-wmf.html
A workround provided in: https://github.com/haraldk/TwelveMonkeys/issues/35 to wrap recent WMF with a "fake" Aldus Placable Header, then pass to Batik.
Otherwise, ImageMagick (IM) is a simple solution with installer. BTW, even with recent IM, WMF could not be properly converted in Linux (return black image).
import org.im4java.core.ConvertCmd;
import org.im4java.core.IM4JavaException;
import org.im4java.core.IMOperation;
import org.im4java.process.ProcessStarter;
import java.io.File;
import java.io.IOException;
public class converter {
public static void main(String arg[]) throws InterruptedException, IOException, IM4JavaException {
String myPath="C:\\Program Files\\ImageMagick-7.0.10-Q16-HDRI";
ProcessStarter.setGlobalSearchPath(myPath);
String input="C:\\Users\\Bagra\\Desktop\\emf files\\two.emf";
String output="C:\\Users\\Bagra\\Desktop\\emf files\\out2.jpg";
convert(input,output);
}
public static void convert(String input,String output)
{
try{
IMOperation img=new IMOperation();
img.addImage();
img.addImage();
ConvertCmd convert=new ConvertCmd()`enter code here`;
convert.run(img,new Object[]{input,output});
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
First thing you have to do is go https://imagemagick.org/script/download.php and download ImageMagick-7.0.10-22-Q16-HDRI-x64-dll.exe if you are on Windows. But bu carefully when you see the installiation options you have to choose install legacy utilities(e.g convert).(This is very important). After you installed just create a simple console application with java.
String myPath="C:\\Program Files\\ImageMagick-7.0.10-Q16-HDRI";
ProcessStarter.setGlobalSearchPath(myPath);
You have to set search path to your installed directory. Then select an emf file and non-exist jpg path. For more details you can follow http://im4java.sourceforge.net/docs/dev-guide.html. I spent a lot of time to figure out. I hope it helps anyone who need something like this. Good luck.
精彩评论