symantis
symantis

Reputation: 11

How to export table in text document (ODT or DOCX) to EMF format via api

I have a text document (ODT or DOCX) with some tables. I use LibreOffice API (in Java) to open this document.

I want to export tables as EMF files. Any ideas? P.S. Official documentation for LibreOffice (OpenOffice) API is very poor. In this very interesting article http://fivedots.coe.psu.ac.th/~ad/jlop/ this information is not found.

Upvotes: 0

Views: 524

Answers (1)

Miklos Vajna
Miklos Vajna

Reputation: 146

There is no ready-to-use LibreOffice API that can do this, but depending on how you decide on the details, I think this is still doable. Couple of tips:

  1. If you want to export tables, first you need to iterate over the table container of the document, XTextTablesSupplier allows you to do this.

  2. Then you probably want to copy out each and every table to a separate Writer document, so when you export a Writer page, only the table shows up there, nothing else. (Keep in mind that tables may span over multiple pages). Copying content between documents is possible using the XTextCopy interface.

  3. Once you have a Writer document that contains just a single table, you need to iterate over all pages of the document: the opened document's component can be casted to an XRenderable, then getRendererCount() tells you about the number of pages. (You could use XPageCursor as well, but the former interface will be needed anyway below.)

  4. Finally once you have a single page of a single document, you can use the XRenderer interface's render() method to actually render a page to a vector format.

I would suggest that you consider if you really want to do all this within LibreOffice itself; you could simplify your job if you replace steps 3. and 4. with exporting to PDF, then handle the PDF to EMF conversion yourself.

Upvotes: 1

Related Questions