Remove an image from a Draw Page

Creating a macro - Writing a Script - Using the API

Remove an image from a Draw Page

Postby cve60069 » Tue Mar 02, 2021 9:07 pm

Hello

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

This is basically what I did

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
    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
cve60069
 
Posts: 16
Joined: Fri Feb 15, 2013 12:31 pm

Re: Remove an image from a Draw Page

Postby JeJe » Tue Mar 02, 2021 11:08 pm

this should remove the drawing:

Code: Select all   Expand viewCollapse view
thiscomponent.drawpages(0).getbyindex(0).dispose
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1598
Joined: Wed Mar 09, 2016 2:40 pm

Re: Remove an image from a Draw Page

Postby FJCC » Tue Mar 02, 2021 11:20 pm

If you just want to remove the image, and not the DrawPage, try
Code: Select all   Expand viewCollapse view
Page.remove(PDF)
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 8217
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove an image from a Draw Page

Postby cve60069 » Wed Mar 03, 2021 7:07 pm

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
cve60069
 
Posts: 16
Joined: Fri Feb 15, 2013 12:31 pm

Re: Remove an image from a Draw Page

Postby Bidouille » Tue Mar 09, 2021 10:37 am

As usual, provide a document to reproduce what is described.
User avatar
Bidouille
Volunteer
 
Posts: 458
Joined: Mon Nov 19, 2007 10:58 am
Location: France


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests