Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6252431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:01+00:00 2026-05-24T13:48:01+00:00

I wanted to see if anyone has done this. In ruby, i’d like to

  • 0

I wanted to see if anyone has done this.

In ruby, i’d like to open a PDF and search for text there. Any text that I find I would like to highlight in yellow, then return the page(s) where I found the text as a jpg. Has anyone done this before?

Thanks,
Craig

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:48:01+00:00Added an answer on May 24, 2026 at 1:48 pm

    If you’re happy to use a c-extension you can achieve this with the ruby-gnome2 bindings. You’ll need the poppler and gdk_pixbuf2 gems.

    The API docs for these gems are a little skimpy, but you can find what there is at http://ruby-gnome2.sourceforge.jp/

    require 'poppler'
    require 'gdk_pixbuf2'
    
    SCALE = 2
    
    filename = "source.pdf"
    doc = Poppler::Document.new(filename)
    page = doc.get_page(0)
    
    # render the page to an in-memory buffer
    width, height = *page.size
    buf = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB, true, 8, width*SCALE, height*SCALE)
    page.render(0, 0, width*SCALE, height*SCALE, SCALE, 0, buf)
    
    # copy the rendered buffer into an pixmap for further editing
    map = Gdk::Pixmap.new(nil, width*SCALE, height*SCALE, 24)
    map.draw_pixbuf(nil, buf, 0, 0, 0, 0, -1, -1, Gdk::RGB::DITHER_NONE, 0, 0)
    
    # setup highlight color and blend function
    gc  = Gdk::GC.new(map) # graphics context
    gc.rgb_fg_color = Gdk::Color.new(65535, 65535, 0)
    gc.function = Gdk::GC::AND
    
    # find each match and highlight it. The co-ordinate maths is ugly but
    # necesary to convert from PDF co-ords to Pixmap co-ords
    page.find_text("the").each do |match|
      matchx = match.x1 * SCALE
      matchy = (height - match.y2) * SCALE
      matchw = (match.x2-match.x1) * SCALE
      matchh = (match.y2-match.y1) * SCALE
      map.draw_rectangle(gc, true, matchx, matchy, matchw, matchh)
    end
    
    # save the buffer to a JPG
    newbuf = Gdk::Pixbuf.from_drawable(nil, map, 0, 0, width*SCALE, height*SCALE)
    newbuf.save("foo.jpg", "jpeg")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just wanted to see if anyone is aware of any other debuggers capable
I have an interesting problem and wanted so see if anyone else has seen
I came up with a solution, but I wanted to see if anyone had
I wanted to see if there is a cleaner and more effective way of
I see there is full ajax mode but I wanted to see if there
Has anyone had any luck using a UIPicker in the 3.2 SDK? I'm in
So I have a rather odd issue that I wanted to see if anyone
I posted on the Carabiner wiki but wanted to see if anyone here was
I have a question and wanted to see if anyone else is familiar with
I am new to Ubuntu and Mercurial, so I wanted to see if anyone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.