[racket] Creating PDF files in Racket

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Tue Dec 10 15:25:56 EST 2013

Thank you John for  your example below.  I'm still not clear where (if
possible) the parameter is for whether the font is embedded in the PDF
document or not.  Is the font embedded by default.

Thanks,
Harry

-------------------------------
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)))


-----------------------------------------


On Mon, Dec 9, 2013 at 11:58 AM, Harry Spier <vasishtha.spier at gmail.com>wrote:

>
> In Racket is it possible to convert a unicode text file into a PDF file
> with an embedded unicode font.  This is for an on-line digital library
> application where I want to create the PDF file on the fly when the user
> requests that output format.
>
> Thanks,
> Harry
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20131210/d8e0a743/attachment.html>

Posted on the users mailing list.