Some test text!

Search
Hamburger Icon

Python / Guides / Remove content

Removing images from PDF page in Python

To remove all images from a document page.

doc = PDFDoc(filename)
page = doc.GetPage(1)

writer = ElementWriter()
reader = ElementReader()
reader.Begin(page)
writer.Begin(page, ElementWriter.e_replacement, False)

element = reader.Next()     # Read page contents
while element != None:
    type = element.GetType()
    if type == Element.e_image or type == Element.e_inline_image:
        pass # remove all images by skipping them
    else:
        writer.WriteElement(element)
    element = reader.Next()

writer.End()
reader.End()

PDF Editor (Programmatic)
Full code sample which strips all images from the page and changes text color to blue.

Get the answers you need: Chat with us