Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Ruby / Guides / Remove content

Platform


Documentation


PDFTron is now Apryse, learn more here.

Removing images from PDF page in Ruby

To remove all images from a document page.

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

writer = ElementWriter.new()
reader = ElementReader.new()
reader.Begin(page)
writer.Begin(page, ElementWriter::E_replacement, false)

element = reader.Next()	 # Read page contents
while !element.nil? do
    type = element.GetType()
    case type
    when Element::E_image, Element::E_inline_image
        # remove all images by skipping them
    else
        writer.WriteElement(element)
    end
    element = reader.Next()
end

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: Support