How to insert pdf file with macro basic as embedded OLE object to Presentation slide?

Recorded with Writer the following macro but it is not showing how to specify filename etc.
Would like to have macro code to embed pdfs to slides e.g. the following way:
slide 1 ← 1.pdf
slide 2 ← 2.pdf

So that the content is shown in the slide instead of “show as icon” link.
And if possible the macro would be neat to be executable in soffice headless mode from command line.

sub embedpdf2
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertObject", "", 0, Array())

end sub

rgrds Paavo

FYI: I have been searching this forum for more information and found this:

embed-ole-into-doc-via-terminal ← no answers

  • this question scratches the surface of my desire

using-lilo-starbase-macros-in-librecalc-transfer-tables-and-charts-to-writer-document ← numerous answers for previous releases and maybe writer as target could be changed to impress slides, but roundtrip to try the snippets in this thread is long.

The challenge is partially reminding me the differences of vbe/vba stuff for old ms office environments, the excel seemed to be the “easiest to develop” what comes to vbe and commanding other office objects: outlook, word, powerpoint.

With LibreOffice it feels that the Tools–>Development Tools vary between Calc,Writer,Impress etc. and to really digout properties of objects is pretty steep process and requires good library of existing macro basic (uno summoning) codes to alter and see the end-result. While one-by-one looking existing macro examples and documentations I have not yet found any examples about embedding OLE objects for any of the LibreOffice family tools. So a link to such example snippet would be nice.

Also link to example how to have headless serverside commands driving macros, would be neat.

And yes targeting to LibreOffice 7.6.1.2 etc. releases.

rgrds Paavo

I don’t have a example for macros but with the gui it should be fairly easy:

  • Goto Insert > OLE objects > OLE object
  • Choose “create from file”
  • select your PDF file

Source: Insert OLE Object

Also maybe @Ratslinger s answer in “Create macro to insert and link a OLE Spreadsheet?” could be of some help.

have look at Apache OpenOffice Community Forum - [Solved] Macro to insert an OLE object - (View topic) . Maybe that also works for a presentation document

1 Like