Remove image from PDF in Python

To remove all images from a document page.

1doc = PDFDoc(filename)
2page = doc.GetPage(1)
3
4writer = ElementWriter()
5reader = ElementReader()
6reader.Begin(page)
7writer.Begin(page, ElementWriter.e_replacement, False)
8
9element = reader.Next() # Read page contents
10while element != None:
11 type = element.GetType()
12 if type == Element.e_image or type == Element.e_inline_image:
13 pass # remove all images by skipping them
14 else:
15 writer.WriteElement(element)
16 element = reader.Next()
17
18writer.End()
19reader.End()

PDF Editor (Programmatic)
Full code sample which strips all images from the page and changes text color to blue. Code sample is available in C++, C#, Java, Python, Go, PHP, Ruby & VB.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales