Question

I came across a problem converting OMML(Math XML in open office) to an image.

This functionality is in my undergoing project which should be deployed on Linux. For efficiency, I should choose a method without MS products (such as dll, MS Office extensions, etc.).

Show some findings:

  1. OMML can be translate to MATHML(by XSLT), then I can convert MATHML to image(by jeuclid).
  2. OMML can be translate to LaTex(by XSLT or writer2tex), then I can convert LaTex to image(by texvc of mediawiki).

But, all these solutions depend on 3rd software or XSLT. Is there a better way to do such a conversion?

Was it helpful?

Solution

I would simply write a macro that would import the OMML into a OOo/AOO/LibreOffice drawing and export that to png, for example.

There are plenty of examples online on how to use OpenOffice Macros with filters.

You can run an openoffice macro from the command line.

Something like this, I do not have the time to look into it more, sorry ...

Sub Macro1(outfile, formula)
   ' Create a drawing.
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() )
   ' Get the first page.
   oDrawPage = oDoc.getDrawPages().getByIndex( 0 ) 
   ' Input and output files - to be converted to URL's
     iURL = ConvertToURL(formula)
     oURL = ConvertToURL(outfile)
   ' Get a position in the drawing (not sure this works in draw, it does in writer)
   set oViewCursor = objDocument.CurrentController.getViewCursor()
   set oTextCursor = objDocument.Text.createTextCursorByRange(oViewCursor.getStart())
   'insert formula
   oTextCursor.InsertDocumentFromURL iFile, Array() 
      ' Save the document using a filter.
   oDoc.storeToURL(oURL, Array(MakePropertyValue("FilterName", "draw_png_Export"), ))
End Sub

To run that from the command line, use the following:

sdraw -invisible "macro:///Standard.Module1.ConvertWordToPDF('c:\formula.odf', 'c:\image.png')"

Regards,

HP

OTHER TIPS

This is the simplest solucion I've found, using the headless option of libreoffice:
1. Locate in the folder where your doc file is ( i.e. test.doc )
2. Close Libreofffice if it's running. Otherwise the following command will do nothing.
3. Run the following command ( in debian and libreoffice 3.5 , other OS and versions may differ )

libreoffice --headless --convert-to html --outdir out test.doc

  1. Explore the out dir, you'll find the html document with the image inside in base64.
  2. Make your own script to automate the previous steps.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top