| 1 | package org.docx4j.openpackaging.parts.WordprocessingML; |
|---|
| 2 | |
|---|
| 3 | import org.docx4j.openpackaging.exceptions.InvalidFormatException; |
|---|
| 4 | import org.docx4j.openpackaging.parts.ExternalTarget; |
|---|
| 5 | import org.docx4j.openpackaging.parts.PartName; |
|---|
| 6 | import org.docx4j.openpackaging.parts.relationships.Namespaces; |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * Summary: At present, EMF files are best converted to SVG using OpenOffice. |
|---|
| 10 | * |
|---|
| 11 | * Note regarding options for converting EMF files to SVG and/or PNG |
|---|
| 12 | * (as at Feb 2010): |
|---|
| 13 | |
|---|
| 14 | - com.adobe.dp.office |
|---|
| 15 | - wmf2svg |
|---|
| 16 | - batik |
|---|
| 17 | - freehep |
|---|
| 18 | - imagemagick |
|---|
| 19 | - openoffice |
|---|
| 20 | |
|---|
| 21 | (Could mono's libgdiplus help? Search for 'mono metafile') |
|---|
| 22 | |
|---|
| 23 | wmf2tosvg is a good solution for WMF, but it has no EMF support. |
|---|
| 24 | |
|---|
| 25 | FreeHEP has EMF2SVG, but the output wasn't much good (perhaps |
|---|
| 26 | because office drawings aren't its primary focus). It would |
|---|
| 27 | also be a very complex dependency. |
|---|
| 28 | |
|---|
| 29 | Batik has WMFTranscoder, but not EMFTranscoder! It looks like |
|---|
| 30 | one could be added from package |
|---|
| 31 | org.eclipse.gmf.runtime.draw2d.ui.render.awt.internal.svg.metafile |
|---|
| 32 | with a bit of work, but still, batik is no good on appengine since |
|---|
| 33 | it uses awt, and spawns threads. So avoid it.. |
|---|
| 34 | |
|---|
| 35 | imagemagick has no support for EMF at all (other than on Windows). |
|---|
| 36 | |
|---|
| 37 | openoffice can be used to convert EMF; I found it worked well. |
|---|
| 38 | |
|---|
| 39 | Until the EMFParser in com.adobe.dp.office is fixed, this may be |
|---|
| 40 | a good option (depending on your environment). |
|---|
| 41 | |
|---|
| 42 | Maybe the code to use openoffice for EMF conversions could go in |
|---|
| 43 | src/docx4j-extras, so only those who wanted to use it would need |
|---|
| 44 | to worry about the dependencies. |
|---|
| 45 | |
|---|
| 46 | TODO: Have a look at cairo, which has java bindings. Can it be used |
|---|
| 47 | to read EMF? See also pymfvu - UniCovertor will ultimately be able |
|---|
| 48 | to import EMF |
|---|
| 49 | * |
|---|
| 50 | */ |
|---|
| 51 | public class MetafileEmfPart extends MetafilePart { |
|---|
| 52 | |
|---|
| 53 | public MetafileEmfPart(PartName partName) throws InvalidFormatException { |
|---|
| 54 | super(partName); |
|---|
| 55 | init(); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | public MetafileEmfPart(ExternalTarget externalTarget) { |
|---|
| 59 | super(externalTarget); |
|---|
| 60 | init(); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | public void init() { |
|---|
| 64 | // Used if this Part is added to [Content_Types].xml |
|---|
| 65 | setContentType(new org.docx4j.openpackaging.contenttype.ContentType( |
|---|
| 66 | org.docx4j.openpackaging.contenttype.ContentTypes.IMAGE_EMF)); |
|---|
| 67 | |
|---|
| 68 | // Used when this Part is added to a rels |
|---|
| 69 | setRelationshipType(Namespaces.IMAGE); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | } |
|---|