Question

I am using LibreOffice 4 and Java Uno API for managing documents.

I've got situation where I am importing HTML documents with img tags to LibreOffice via Java Uno API and save document in other formats (such as odt, docx, doc, rtf).

The problem is that LibreOffice converts img tags to graphic objects with links (not embedded in document).

I was trying to use html base64 but it seems that LibreOffice doesn't support that.

Now I want to convert these linked graphic objects to embedded graphics objects.
I am able to iterate through images via XTextGraphicObjectsSupplier but I can't figure it out how to make these objects embedded.

Is it possible?

Maybe it is possible to make some magic attribute in html img tag and LibreOffice will embed it?

Was it helpful?

Solution

It seems that libre/open office doesn't support this option. Only way is to remove and again insert embedded image, but you must be aware of formating (e.g. size etc.). I achieved my goal by doing these steps (WARN it is hack...):

  1. Save HTML to odt. In this odt graphics are linked to files on disk.
  2. Unzip odt file.
  3. Create directory Pictures in unzipped directory and move there all images.
  4. Edit content.xml and replace path to system files to Pictures/file-name.
  5. Edit META-INF/manifest.xml and something like this <manifest:file-entry manifest:media-type="image/png" manifest:full-path="Pictures/file-name"/>
  6. Zip folder and change extension to odt.
  7. Read odt file via Libre/Open Office Java Uno API. Now this document has embedded graphic objects.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top