[racket] Snips displaying pdfs

From: Michael W (mwilber at uccs.edu)
Date: Sat May 12 19:09:58 EDT 2012

(What's racket's policy on posting our own work to the mailing
list? Sorry if this seems like spam.)

(planet gcr/render-pdf) now implements more of the libpoppler
glib API. You can now render PDF files to picts or bitmap%s,
gather the locations of all letters on the page, or can search
for strings of text.

Try this snippet out:

#lang racket
(require slideshow/pict
         (planet gcr/pdf-render))

(define page (pdf-page "oopsla04-gff.pdf" 0))
;; The first page of a PDF file. (Pages are zero-indexed)

;; Replace the above with your own PDF file, of course.
;; Show the location of each of the "the" words on this page, and
;; overlay each bounding box over the PDF.
 (for/fold ([pageview (page->pict page)])
    ([bounding-box (in-list (page-find-text page "the"))])
  (match-define (list x1 y1 x2 y2) bounding-box)
  (pin-over pageview x1 y1
             (colorize (filled-rectangle (- x2 x1) (- y2 y1)) "yellow")

Examples and docs:

Let me know if you have comments/complaints/questions! :)

Enjoy your evening,

Posted on the users mailing list.