pdf-render: Render PDF files to dc% and picts
This library lets Racket draw PDF files to picts and to dc%
objects. It’s quite hacky and minimal; only including auxiliary
functions to get the page count and page size for now.
This requires libpoppler, and likely only works on Linux or Mac
OSX. Windows might work if you insctall Poppler.
1 Examples
To display a rotated version of the first page of a PDF to the screen, use:
(show-pict (rotate (pdf-page->pict "./test.pdf" 0) (* 0.25 pi)))
If the PDF is password-protected, you may have to use:
(define p (pdf-file "./test.pdf" "secret")) (show-pict (rotate (pdf-page->pict p 0) (* 0.25 pi)))
2 PDF file info
This struct allows you to open PDF files from an arbitrary Poppler URI
("file:/tmp/test.pdf" for example) and optionally protected
with a password. Note that the URI must be an absolute path.
(page-count path) → exact-integer? path : (or/c pdf-file? path?)
Returns the number of pages in path.
(page-size doc page_index) → (list/c real? real?) doc : (or/c pdf-file? path?) page_index : (exact-integer?)
Returns the width and height of the page_indexth page. Note that
page_index starts at 0.
This is the page size, not the bounding/crop box! We don’t respect that; sorry.
(render-doc-to-dc! doc page_index dc) → any/c doc : (or/c pdf-file? path?) page_index : (exact-integer?) dc : (is-a?/c dc%)
Renders the page_indexth page, without rasterization, to the
given drawing context.
(pdf-page->pict doc page_index) → pict? doc : (or/c pdf-file? path?) page_index : (exact-integer?)
Produces a pict containing the page_indexth page.
3 Bugs and Issues
Rendering works by reaching into the dc% and pulling out the cairo drawing context. This is inappropriately low-level.