2

Problem:

I have a an image of Enhanced Metafile Fromat Plus Extension EMF+. I need to convert this file to to a PNG image file with java.

Attempts to resolve problem in java:

  1. Apache Batik does not support EMF+ format (Batik supports WMF only format).

  2. FreeHEP does not support EMF+ too. It can convert EMF to SVG and then SVG to PNG. I hoped it can help:

    EMF2SVG.main( new String[] {inputMetaFileName,ontputSvgFileName});
    

    this statement must convert EMF to SVG, but gives an exception:

    java.lang.NullPointerException at org.freehep.graphicsio.exportchooser.AbstractExportFileType.getGraphics(AbstractExportFileType.java:261) at org.freehep.graphicsio.exportchooser.AbstractExportFileType.exportToFile(AbstractExportFileType.java:248) at org.freehep.graphicsio.exportchooser.AbstractExportFileType.exportToFile(AbstractExportFileType.java:282) at org.freehep.graphicsio.emf.EMFConverter.export(EMFConverter.java:81) at org.freehep.graphicsio.emf.EMF2SVG.main(EMF2SVG.java:27)

  3. I used code from here:

    try {
        // read the EMF file
        EMFRenderer emfRenderer = new EMFRenderer( new EMFInputStream(
            new ByteArrayInputStream(emfBytes)));
    
        EMFPanel emfPanel = new EMFPanel();
        emfPanel.setRenderer(emfRenderer);
    
        // prepare Graphics2D
        FileOutputStream svg = new FileOutputStream("svg.svg");
        SVGGraphics2D graphics2D = new SVGGraphics2D (svg, emfPanel);
    
        // export to SVG
        graphics2D.startExport();
        emfPanel.print(graphics2D);
        graphics2D.endExport();
        svg.flush();
        svg.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    This code creates SVG file, but it file has no image.

Ilya Rochev
  • 157
  • 1
  • 3
  • 13
  • Duplicate of http://stackoverflow.com/questions/14279104/convert-wmf-to-png-bmp-jpg ? – BretC Apr 10 '15 at 13:16
  • A little. EMF and WMF are various formats. WMFTranscoder does not support EMF and batik does not have EMFTranscoder. I try to find other way to convert WMF to PNG (or JPEG). I found code here [link](https://mail-archives.apache.org/mod_mbox/poi-dev/201501.mbox/%3CCAKps1KYNdVE4tuQM97Vn85KvSkUr4+8cRjE4w1s_asOHUFujqg@mail.gmail.com%3E) but it does not work. I used freeHeep EMF2SVG but it does not work too. – Ilya Rochev Apr 10 '15 at 20:44
  • Waht is your question? If it's is there a tool that does EMF conversion it's off topic and if it's can you write an EMF converter for me as an answer it's too broad. – Robert Longson Apr 11 '15 at 18:36
  • @RobertLongson i need programmatically to convert EMF image to other viewable format. java code should not call command-line tools. it can use only vector graphics libraries. I found only Batik and FreeHEP but they did not help me. Maybe somebody can use Batik or FreeHEP or other library to convert EMF. – Ilya Rochev Apr 11 '15 at 19:12

0 Answers0