[racket] Snips displaying pdfs
(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.
(show-pict
(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
(cellophane
(colorize (filled-rectangle (- x2 x1) (- y2 y1)) "yellow")
0.5))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Examples and docs:
http://planet.racket-lang.org/package-source/gcr/pdf-render.plt/2/0/planet-docs/main/index.html
Let me know if you have comments/complaints/questions! :)
--
Enjoy your evening,
_mike