[Issue] [Writer] Document background image

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

[Issue] [Writer] Document background image

Post by jeanmi2403 »

Good afternoon,
There is a difference that I don't quite understand between Ooo and LibO on the document background.
With the following code:

Code: Select all

Doc = ThisComponent
StyleFamilies = Doc.StyleFamilies
PageStyles = StyleFamilies.getByName("PageStyles")
DefPage = PageStyles.getByName("First Page")
DefPage.BackGraphicURL=convertToUrl("I:\TrvOpen\Modeles\Fond-Confidentiel.png")
Xray DefPage
The background is displayed well (provided that the page has the "First Page" style)
on OpenOffice, Xray gives this:
Open Office Features
Open Office Features
BackGraphicURL-Ooo.png (61.33 KiB) Viewed 1722 times
On LibreOffice it gives:
Libre Office features
Libre Office features
BackGraphicURL-LibO-16.png (23.19 KiB) Viewed 1722 times
There is therefore a big difference for the BackGraphicURL property between the two suites, which is nevertheless declared of type String in libO, but which hides a complex structure considered as a graphic object.
I can no longer find the name of the image file installed in the background of the page. Apart from a FillBitmapName property which contains different things over time, at this time "Bitmap 3" I understand that this is perhaps the reference in the list of graphic objects embedded in the ZIP file.

I think the evolution serves to standardize style management but what puzzles me is that there must be a mechanism in LibreOffice to process the URL and install the image, because the assignment is done similarly (BackGraphicURL = "Image URL")
LibO also has the BackGraphic property (exactly the same as BackGraphicURL), itself containing the read-only and always empty OriginURL property....

So, in conclusion, it works, but it raises questions...
Cordially
Last edited by Hagar Delest on Sun May 21, 2023 10:59 pm, edited 1 time in total.
Reason: tagged Issue.
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Writer] Document background image

Post by JeJe »

LO (using MRI in my case) has a whole series of Fill properties including the FillBitmap - the image. OO has none of these.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: [Writer] Document background image

Post by jeanmi2403 »

Hello,
JeJe wrote: Wed May 17, 2023 6:46 pm LO has a whole series of Fill properties including the FillBitmap - the image. OO has none of these.
I saw well.
And so ?
Does this change anything about the problem?
There is nowhere the name of the image nor its URL...
Even if there are additional properties compared to Ooo, it is a bug or a regression.
Moreover FillBitmapURL is exactly the same as BackGraphicURL and BackGraphic. What is it for ?
Cordially,
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: [Writer] Document background image

Post by musikai »

Libreoffice doesn't support linked images as background. You can open an OpenOffice file with a linked background in LibreOffice but as soon as you save it will be embedded. The same when you set it via macro.
In LO4,5: You then get this back as BackGraphicURL:

Code: Select all

vnd.sun.star.GraphicObject:10000000000001E50000017FE7960B28
which is an internal address to the picture file in the .odt and isn't easy to work with.

In LO7 things seem again to have changed and BackGraphicURL isn't readable and I have no clue further.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: [Writer] Document background image

Post by jeanmi2403 »

Hello
musikai wrote: Sat May 20, 2023 1:14 pm Libreoffice doesn't support linked images as background.
On the french forum, cwolan give a solution :

Code: Select all

Sub FondPage

   Doc = ThisComponent
   StyleFamilies = Doc.StyleFamilies
   PageStyles = StyleFamilies.getByName("PageStyles")
   DefPage = PageStyles.getByName("First Page")
   
   imgPath = "/home/jeanmi/Documents/Tests/Fond-Confidentiel.png"
   
   myIMG = getGraphFromUrlAsLink(imgPath)
   
   DefPage.BackGraphic = myIMG

End Sub

function getGraphFromUrlAsLink(sFileUrl as String ) as Object 
  oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") 
  Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue 
  oPropsIN(0).Name  = "URL" 
  oPropsIN(0).Value = converttoURL(sFileUrl)
  oPropsIN(1).Name  = "LoadAsLink" 
  oPropsIN(1).Value = TRUE
  getGraphFromUrlAsLink = oProvider.queryGraphic(oPropsIN()) 
end function
After, i see the URL of the image in BackGraphic.OriginURL, BackGraphicURL.OriginURL and FillBitmapURL.OriginURL, no Pictures folder in the odt (zip) and find xlink:href="../Fond-Confidentiel.png" in the file Styles.Xml of the odt.
So the image is linked and not embedded.
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: [Writer] Document background image

Post by musikai »

At first sight it may look as if that function also works for background images.

Since LO 6 this function is needed for any linked image so i used something like for normal images:

Code: Select all

		    	if val(replace(replace(getOfficeVersion,"Dev",""),"LibreOffice",""))>6 then
				g.Graphic = getgraphfromurlaslink(oldurl)
				else
 			    g.GraphicURL = oldurl
				end if
But with linked background images I experience this in Version: 7.4.6.2 (x64) on Win 10:
Apply the background in LO with the function and save. Then open again, type any text and save. Then open again and the background image has turned into a blue background.
Or:
When I add it in LibreOffice with the function it also opens fine in OpenOffice (and the linked image can be accessed with BackgroundURL there. )
When I now save this in OO the image also gets embedded into the .odt (but it is still linked)
When you open this again in LO and save and then reopen the background image has turned into a blue background.

But this all might just be a 7er bug. LO5 will embed any linked background file on saving and it is still there when reopening (also in 7er)
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
User avatar
jeanmi2403
Posts: 29
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: [Writer] Document background image

Post by jeanmi2403 »

Indeed, I have the same experience, there is still a bug...
Jean-Michel
LibO 7.4.7 and AOO 4.1.14 on Windows 10 x64, Windows 11 & Ubuntu 22.04
LibO 7.5 on OpenSuse & Linux MX
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: [Writer] Document background image

Post by cwolan »

I never claimed that the macro solves the problem.

Two bug reports on LibreOffice Bugzilla (both pointed out in the topic on the French forum) are relevant:
  • tdf#127025
    Background image of Writer form cannot be set using the BackGraphic property
  • tdf#90273
    Formatting Regression: Filling background page image can't be linked anymore, only embedded
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 7.6.6
Windows 7,10,11 64-bit
Post Reply