Script for removing all the images from a pdf.

I am useing the code:

Sub DeleteAllPics()
Dim oDoc As Object
Dim oDrawPage As Object
Dim oShape As Object
Dim iShape As Integer
Dim iSheet As Integer
oDoc = ThisComponent
For iSheet = 0 To oDoc.getSheets().getCount() - 1
oDrawPage = oDoc.getSheets().getByIndex(iSheet).getDrawPage()
For iShape = oDrawPage.getCount() - 1 To 0 Step -1
oShape = oDrawPage.getByIndex(i)
oDrawPage.remove(oShape)
Next iShape
Next iSheet
End Sub

(snippet reformatted by ajlittoz)

From the post [Writer] How to remove all pictures from a document? - #4 by Carrbigdog. But when I try to run it, I get the error message:

BASIC runtime error.

Property or method not found: getSheets.

I would appreciate any information on how to fix this.

A general remark as I don’t practice macros.
A Draw document (into which a PDF is “converted” when you open it) is exclusively made of shapes. Even text is seen as a collection of (graphical) text boxes. By using such a macro which was intended for Writer, may result in removing everything as everything is a graphical shape.

Something like that, now without an error by “remove”
there aren’t “sheets” in draw

Sub ImagesRemove()
Dim oDoc, oPage, oShape
Dim nNumOfShapes As Integer
Dim nNumOfImage As Integer
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
nNumOfImage = 0
Dim i As Integer
oDoc = ThisComponent
document   = ThisComponent.CurrentController.Frame
dim args1(0) as new com.sun.star.beans.PropertyValue
AnzPages = oDoc.getDrawPages.getCount()
For j = 0 To AnzPages -1
oPage = oDoc.DrawPages(j)
nNumOfShapes = oPage.getCount()
For i = 0 To nNumOfShapes -1
oShape = oPage.getByIndex(i)
      If oShape.supportsService("com.sun.star.drawing.GraphicObjectShape") then
    ThisComponent.CurrentController.select(oShape)
    'ThisComponent.CurrentController.remove(oShape)
    dispatcher.executeDispatch(document, ".uno:Delete", "", 0,args1())
'    nNumOfImage=nNumOfImage+1
end if
Next
Next
End Sub