Page 1 of 1

Remove an image from a Draw Page

PostPosted: Tue Mar 02, 2021 9:07 pm
by cve60069
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

Re: Remove an image from a Draw Page

PostPosted: Tue Mar 02, 2021 11:08 pm
by JeJe
this should remove the drawing:

Code: Select all   Expand viewCollapse view
thiscomponent.drawpages(0).getbyindex(0).dispose

Re: Remove an image from a Draw Page

PostPosted: Tue Mar 02, 2021 11:20 pm
by FJCC
If you just want to remove the image, and not the DrawPage, try
Code: Select all   Expand viewCollapse view
Page.remove(PDF)

Re: Remove an image from a Draw Page

PostPosted: Wed Mar 03, 2021 7:07 pm
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.

Re: Remove an image from a Draw Page

PostPosted: Tue Mar 09, 2021 10:37 am
by Bidouille
As usual, provide a document to reproduce what is described.