[racket] Snips displaying pdfs

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue May 8 01:43:40 EDT 2012

2012/5/8 Michael W <mwilber at uccs.edu>:
> Sure, but I mean, is there a better way to get at a dc<%>'s cairo
> context than (require racket/draw/private/local) ? From what I
> understand, those areas aren't meant to be used by third-party
> libraries, and definitely not by planet packages. Not all dc<%>s
> are even backed by cairo contexts...

I believe you want get-handle. It will give you the surface of a bitmap,
and you can then get a context.

(let* ([bitmap    (make-bitmap WIDTH HEIGHT)]  ; works
       [document  (poppler_document_new_from_file (string-append
"file:" filename) #f #f)]
       [page      (poppler_document_get_page document 0)]
       [surface   (send bitmap get-handle)]
       [context   (cairo_create surface)])
  (cairo_scale context 2.0 2.0)
  (poppler_page_render page context)
  (make-object image-snip% bitmap))

This example is from


/Jens Axel

> 16 minutes ago, Eli Barzilay wrote:
>> Three hours ago, Michael W wrote:
>> >
>> > I'm not rasterizing to a bitmap% or anything like that. Instead,
>> > I'm asking poppler to draw directly to the dc<%>'s cairo context
>> > (Eli and Matthew are probably cringing), which means that you can
>> > render to arbitrary dc<%> objects at the cost of being much more
>> > hacky than your version.
>> I don't know about "hacky" -- it just sounds like it'll invoke the
>> library for every redraw, which would be overall slower than going
>> through a bitmap that saves the results.
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

Jens Axel Søgaard

Posted on the users mailing list.