[racket] Creating PDF files in Racket

From: John Griffin (jg at ittalentteam.com)
Date: Mon Dec 9 20:01:44 EST 2013

Does this get you started?
---------------
#lang racket

(require racket/draw)

(define (text->pdf text output-file)
  
  (define font (make-font #:size 14
                          #:size-in-pixels? #t
                          #:face "Mono"))
  (define (up-int x) (inexact->exact (ceiling x)))
  (define (make-bm w h) (make-object bitmap% w h #f #t))
  (define lines (regexp-split "\n" text))
  (define dc
    (new pdf-dc%
         [ interactive #f ]
         [ use-paper-bbox #f ]
         [ width 592 ]
         [ height 756 ]
         [ output output-file ]))
  
  (send* dc
    (start-doc "useless string")
    (start-page))
  
  (send dc set-font font)
  
  (let loop ((lines lines)
             (width 0)
             (height 0))
    (when (pair? lines)
      (let-values (((w h d v) (send dc get-text-extent (car lines))))
        (send dc draw-text (car lines) 0 height)
        (loop (cdr lines)
              (max width (up-int w))
              (+ 5 height (up-int h))))))
  
  (send* dc 
    (end-page)
    (end-doc)))


------
John Griffin, CTO
IT Talent Team, LLC
www.ittalentteam.com
855-488-8326









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131209/901dd3c4/attachment-0001.html>

Posted on the users mailing list.