Bug 119872 - add an option to extract and link all pictures from a writer document
Summary: add an option to extract and link all pictures from a writer document
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.1.0.3 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-14 09:14 UTC by Oliver Brinzing
Modified: 2018-11-03 14:43 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
ExtractWriterGraphics (4.04 KB, text/plain)
2018-09-14 09:14 UTC, Oliver Brinzing
Details
ExtractWriterGraphics (LO 6.1) (1.96 KB, text/plain)
2018-11-03 14:42 UTC, Oliver Brinzing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Brinzing 2018-09-14 09:14:18 UTC
Created attachment 144860 [details]
ExtractWriterGraphics

attached macro will extract all pictures from a writer document and link it:

- open a writer document containing pictures
- optional: rename pictures with meaningfull names
- run macro:
  - a *.bak file is created
  - all pictures will be stored in a folder "pictures"
  - the document is stored without the pictures, 
    all pictures are linked now.

this worked until LO 6.0 but will fail due to change of GraphicURL in LO 6.1,
cause it is no longer possible to access the "vnd.sun.star.GraphicObject:" URLs.

this macro was very usefull, for example if one has to "refactor" large document containing dozens of pictures. once pictures are exported, one can easily edit/exchange it or even share it with other documents.

i suggest adding an API to access pictures again, and/or add a global function to LO writer so all users can benefit from it.
Comment 1 Roman Kuznetsov 2018-09-14 13:54:37 UTC
If you already a code for it, you can make an extension and publish it on extensions.libreoffice.org

I use special extension for create own extension from existing macroses - BasicAddonBuilder (https://wiki.openoffice.org/wiki/Extensions_Packager ,  http://calc-info.de/files/BasicAddonBuilder_LibreOffice_0.5.2.oxt). It works fine into LO 5.2 on Windows
Comment 2 Jean-Baptiste Faure 2018-09-16 08:40:01 UTC
Are you sure there is no other way to do the same thing? Did you ask on the developer mailing list?

Status set to NEEDINFO, please set it back to UNCONFIRMED once requested
informations are provided.

Best regards. JBF
Comment 3 Oliver Brinzing 2018-09-16 09:23:39 UTC
i found an announcement with discusson:

API-CHANGE - dropping string properties which use vnd.sun.star.GraphicObject URL

http://document-foundation-mail-archive.969070.n3.nabble.com/API-CHANGE-dropping-string-properties-which-use-vnd-sun-star-GraphicObject-URL-td4235349.html

for example:

> How should we find out if a image is embeded in the doc or not ?
> we uses for now:
> if left(oCheckgraphic1.GraphicURL,27) <> "vnd.sun.star.GraphicObject:" then

that is exactly, what i need to make the macro work again.
Comment 4 Oliver Brinzing 2018-09-16 09:30:47 UTC
if one tries to access the Property "GraphicURL":

ThisComponent.GraphicObjects.getByIndex(0).GraphicURL

an exception is thrown:
"GraphicURL, Getting from this property is not unsupported"
Comment 5 Jean-Baptiste Faure 2018-09-25 06:57:08 UTC
(In reply to Oliver Brinzing from comment #4)
> if one tries to access the Property "GraphicURL":
> 
> ThisComponent.GraphicObjects.getByIndex(0).GraphicURL
> 
> an exception is thrown:
> "GraphicURL, Getting from this property is not unsupported"

Same issue with the picextract extension: https://extensions.libreoffice.org/extensions/extract-embedded-images-and-replace-embedded-images-with-linked-images-picextract

I think that this API change produces a regression and the API should give another way to do the same thing. I suggest you to open a bug report for that.

Best regards. JBF
Comment 6 Tomaz Vajngerl 2018-10-24 11:19:16 UTC
> (In reply to Oliver Brinzing from comment #4)
> I think that this API change produces a regression and the API should give
> another way to do the same thing. I suggest you to open a bug report for
> that.

No that's not a regression - it is an ESC approved API change. "GraphicURL" properties have been deprecated and replaced by "Graphic" property. "GraphicURL" properties are now write only (so you can create a Graphic by specifying a external URL) but can't be read back because the vnd.sun.star.GraphicObject internal URLs don't exist anymore so there is nothing to return back.

To determine if a Graphic is internal or external there is now "Linked" property on the Graphic object (XGraphic returned by "Graphic" property). 

To change the graphic now you need load it with GraphicProvider::queryGraphic and
add set "LoadAsLink" to true in the input parameter mediaProperties. Once the graphic is loaded (you have the XGraphic object), you can set it using "Graphic" property instead of "GraphicURL".
Comment 7 Oliver Brinzing 2018-11-03 14:42:49 UTC
Created attachment 146268 [details]
ExtractWriterGraphics (LO 6.1)

(In reply to Tomaz Vajngerl from comment #6)

i think i got it, attached a new macro, thx for guiding me