[Solved] Embed images in HTML export

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

[Solved] Embed images in HTML export

Post by martinrame »

Hi, I'm converting rtf documents to HTML using LibreOffice 6.2.8.2 20(Build:2) with Python UNO and noticed the html doesn't include the embedded images.

I've been googling about this and found this should work

soffice --convert-to html:HTML:EmbedImages file_to_convert

To convert the file I'm using this:

Code: Select all

outProps = (
    PropertyValue( "FilterName" , 0, 'HTML' , 0 ),
    PropertyValue( "EmbedImages" , 0, True , 0 ),
    PropertyValue( "Overwrite" , 0, True , 0 ),
    PropertyValue( "OutputStream", 0, OutputStream(), 0)
    )

try:
    filename="/home/informemedico/rtftoimpacs/salida.html"
    # document.storeToURL("file://" + filename, outProps)
    document.storeToURL("private:stream", outProps)
    document.dispose();
except IOException as e:
    sys.stderr.write(filename)
    sys.stderr.write("Error: " + e.Message)
As you can see I added the PropertyValue "EmbedImages", but it doesn't embed the images as Base64 in the output.
Last edited by martinrame on Sat Sep 11, 2021 11:28 pm, edited 1 time in total.
LibreOffice 7.1 on FreeBSD 12.2
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Re: Embed images in HTML export

Post by ms777 »

... I believe the outProps argument must be constructed differently. Have a look at viewtopic.php?t=22655 for impress export to html

Good luck,

ms777
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

ms777 wrote:... I believe the outProps argument must be constructed differently. Have a look at viewtopic.php?t=22655 for impress export to html

Good luck,

ms777
Hi ms777, my code works ok, the only problem is that it isn't including the images nor writing them as external files.
LibreOffice 7.1 on FreeBSD 12.2
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

I tried "libreoffice --headless --convert-to html:HTML:EmbedImages in.rtf out.html" and the output does contain the embedded images.

I need to figure out how the "html:HTML:EmbedImages" filter maps to UNO.
LibreOffice 7.1 on FreeBSD 12.2
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

I did try passing HTML:EmbedImages as the FilterName:

Code: Select all

outProps = (
    PropertyValue( "FilterName" , 0, 'HTML:EmbedImages' , 0 ),
    PropertyValue( "Overwrite" , 0, True , 0 ),
    PropertyValue( "OutputStream", 0, OutputStream(), 0)
    )
But I got this error:

Code: Select all

Error: SfxBaseModel::impl_store <private:stream> failed: 0x81a(Error Area:Io Class:Parameter Code:26)
So, that's not the property I'm looking for.
LibreOffice 7.1 on FreeBSD 12.2
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embed images in HTML export

Post by Villeroy »

Does HTML support embedded images?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

Villeroy wrote:Does HTML support embedded images?
Yes.

Also please read my previous response, LibreOffice is capable of generating HTML with embedded images from RTF files by using this:

Code: Select all

libreoffice --headless --convert-to html:HTML:EmbedImages in.rtf out.html
LibreOffice 7.1 on FreeBSD 12.2
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

BTW, I don't care about embedded images, *at least* I want LO to generate images as external files with

Code: Select all

<img src=..>
links in the HTML. But currently I'm only getting the HTML without images.
LibreOffice 7.1 on FreeBSD 12.2
martinrame
Posts: 14
Joined: Tue Dec 13, 2016 10:07 pm

Re: Embed images in HTML export

Post by martinrame »

I found the solution, had to append the FilterOptions Property with a value of "EmbedImages":

Code: Select all

outProps = (
    PropertyValue( "FilterName" , 0, 'HTML' , 0 ),
    PropertyValue( "FilterOptions" , 0, 'EmbedImages' , 0 ),
    PropertyValue( "Overwrite" , 0, True , 0 ),
    PropertyValue( "OutputStream", 0, OutputStream(), 0)
    )
LibreOffice 7.1 on FreeBSD 12.2
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: [Solved] Embed images in HTML export

Post by Mr.Dandy »

martinrame wrote:I found the solution, had to append the FilterOptions Property with a value of "EmbedImages"
I'm curious. Could you provide a sample HTML document with one embeded picture?

In the past, only CHM file (Microsoft inside) has this capacity.
OpenOffice 4.1.12 - Windows 10
Post Reply