Description: Tying to insert a linked graphicobject via ThisComponent.createInstance("com.sun.star.text.GraphicObject") and oText.insertTextContent(oCursor, oGraph, False) leads to an empty image frame (loading error) Steps to Reproduce: Customize the image url and run this Basic code: Sub InsertGraphicObject Dim oDoc Dim sURL Dim oCursor Dim oGraph Dim oText sURL= ConvertToUrl("C:\Users\username\image.jpg") oDoc = ThisComponent oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.gotoStart(False) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") With oGraph .GraphicURL = sURL .Width = 6000 .Height = 8000 End With oText.insertTextContent(oCursor, oGraph, False) End Sub Actual Results: An empty image frame appears saying "Loading Error" Expected Results: The image should be inserted correctly and appear. Reproducible: Always User Profile Reset: No Additional Info:
Confirmed with Ubuntu 18.04 and Version: 6.1.1.0.0+ Build ID: 30c178dcb3301527ad92bbd245d1525ab77e314e The macro works as expected in 6.0.5 and 6.2Alpha
This could be related to a resolved issue from the changes to how images are handled. See: https://bugs.documentfoundation.org/show_bug.cgi?id=117427
Will add Tomaž Vajngerl to CC, perhaps he would know on that.
@Raal, is it the same case you investigated with Miklos in the Hamburg Hackfest?
Kai Struck, Could you please read the comments in bug 117427 to help you adapt your code?
Xisco Faulí, Ok, after reading it and using the function getGraphFromUrlAsLink for oGraph.Graphic I can make the above example code work: Sub InsertGraphicObject Dim oDoc Dim sURL Dim oCursor Dim oGraph Dim oText sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg") oDoc = ThisComponent oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.gotoStart(False) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") oGraph.Graphic = getgraphfromurlaslink(sURL) With oGraph rem .GraphicURL = sURL .Width = 6000 .Height = 8000 End With oText.insertTextContent(oCursor, oGraph, False) 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 To get the URL of the image we now must use oGraph.Graphic.OriginURL instead of oGraph.GraphicURL If that means that all older code has to be adapted (possibly with a version check to make it compatible with older versions) then I'm not too happy about that.
With simple version check for compatibility for older Versions (just for info, still hoping not being forced to use it): Sub InsertGraphicObject Dim oDoc Dim sURL Dim oCursor Dim oGraph Dim oText sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg") oDoc = ThisComponent oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.gotoStart(False) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") if Officeversion="LibreOffice6.1" then oGraph.Graphic = getgraphfromurlaslink(sURL) else oGraph.GraphicURL = sURL end if With oGraph .Width = 6000 .Height = 8000 End With oText.insertTextContent(oCursor, oGraph, False) if Officeversion="LibreOffice6.1" then msgbox oGraph.Graphic.OriginURL else msgbox oGraph.GraphicURL end if 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 function Officeversion GlobalScope.BasicLibraries.loadLibrary("Tools") Officeversion = GetProductName() end function
Hallo, will the api changes go into any version higher than 6.0.x.x? If so then I would use a version check like: if val(replace(Officeversion,"LibreOffice",""))>6 then oGraph.Graphic = getgraphfromurlaslink(sURL) else oGraph.GraphicURL = sURL end if function Officeversion If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools") Officeversion = GetProductName() end function
I have just tested the code from comment 6, as is, in Apache OpenOffice 3.4.1. And it just works. The API used there should be working down to OOo 3.3.0 (in 3.2.0, neither that, nor previous code would work). So - what is the reason for version checks suggested in comments 7 and 8?
Ah, sorry - not "as is"; just with uncommented ".GraphicURL = sURL" line, which also doesn't give problems here with LO 6.2.2.1 (and could be wrapped into On Error Resume Next ... On Error Goto 0).
@ Mike Kaganski The Code from Comment 6 only "seems" to work without problems in older LO versions and OO. But it doesn't link the image. the image will be embedded. At least on all my tests here. Therefore the version checks.
Ah, ok , forget my previous answer, I misread your comment 10. You are right! It should work for all versions (LO and OO) with this code: Sub InsertGraphicObject Dim oDoc Dim sURL Dim oCursor Dim oGraph Dim oText sURL= ConvertToUrl("http://pmg.pmgroup.be/enews/deroulard/exploit1.jpg") oDoc = ThisComponent oText = oDoc.getText() oCursor = oText.createTextCursor() oCursor.gotoStart(False) oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject") oGraph.Graphic = getgraphfromurlaslink(sURL) With oGraph .GraphicURL = sURL .Width = 6000 .Height = 8000 End With oText.insertTextContent(oCursor, oGraph, False) 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
Dear Kai Struck, To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year. There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present. If you have time, please do the following: Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/ If the bug is present, please leave a comment that includes the information from Help - About LibreOffice. If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice. Please DO NOT Update the version field Reply via email (please reply directly on the bug tracker) Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case) If you want to do more to help you can test to see if your issue is a REGRESSION. To do so: 1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/ 2. Test your bug 3. Leave a comment with your results. 4a. If the bug was present with 3.3 - set version to 'inherited from OOo'; 4b. If the bug was not present in 3.3 - add 'regression' to keyword Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa Thank you for helping us make LibreOffice even better for everyone! Warm Regards, QA Team MassPing-UntouchedBug