Remove an image from a Draw Page

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cve60069
Posts: 16
Joined: Fri Feb 15, 2013 12:31 pm

Remove an image from a Draw Page

Post by cve60069 »

Hello

I have inserted an Image into a Draw Page using Basic.

This is basically what I did

Code: Select all

Dim Doc As Object
Dim Page As Object
Dim PDF As Object
'pdf postion and size
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size

    Doc = ThisComponent

'First Point on all pages
    Point.x = 0
    Point.y = 0
'Size of all pages
    Size.Width = 21000 'A4
    Size.Height = 29700

    Page = Doc.DrawPages(0)
    Page.Name = "PDF1"
    PDF= Doc.createInstance("com.sun.star.drawing.GraphicObjectShape")
    PDF.Size = Size
    PDF.Position = Point
    PDF.GraphicURL = DocPath 'DocPath being the URL of the pdf
    Page.add(PDF)
I then do some other code and save the drawing. Everything works fine. Now I want to delete the Image and start again. I need soemthing like this.

Code: Select all

    Page = Doc.Drawpages.GetByName("PDF1") 'This is the only page in the document.
    Doc.Drawpages.remove(Page)
Works if I have more than one page but not the first page. Any help appreciated
Last edited by MrProgrammer on Tue Mar 02, 2021 10:10 pm, edited 1 time in total.
Reason: Moved from Draw forum to Macros and UNO API
OpenOffice 3.4.1 on Windows 7
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Remove an image from a Draw Page

Post by JeJe »

this should remove the drawing:

Code: Select all

thiscomponent.drawpages(0).getbyindex(0).dispose
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove an image from a Draw Page

Post by FJCC »

If you just want to remove the image, and not the DrawPage, try

Code: Select all

Page.remove(PDF)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
cve60069
Posts: 16
Joined: Fri Feb 15, 2013 12:31 pm

Re: Remove an image from a Draw Page

Post by cve60069 »

Thanks for the advise.

I tried Page.Remove(PDF) but to no avail. To get around the problem, I close the document Doc.Close and then I open it again and then continue. It works but the screen does flash a lot as it opens, saves the contents and then closes again.

I hope others reading this may know a better solution.
OpenOffice 3.4.1 on Windows 7
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Remove an image from a Draw Page

Post by Bidouille »

As usual, provide a document to reproduce what is described.
Post Reply