[cl-typesetting-devel] Non-macro interface to building documents.

Marc Battyani marc.battyani at fractalconcept.com
Tue Feb 10 22:56:15 UTC 2004


Erik Enge <erik at nittin.net> writes

> I have a list of objects.  Each object has three slots: name,
> telephone, age.  I'd like to make
> a PDF document that displays this information in neat tables.  The only
> thing I don't know is
> how many objects there are in my list.
>
> (defun testpdf (&optional (file #P"/tmp/test.pdf"))
>    (pdf:with-document ()
>      (pdf:with-page ()
>        (pdf:with-outline-level ("Example" (pdf:register-page-reference))
> (pdf:set-line-width 0.1)
> (let ((content
>        (typeset::compile-text ()
>                   (typeset:paragraph (:font "Helvetica-Bold" :font-size
> 16)
>                     "Test document")
>                   (typeset:hrule :dy 2)
>                   (typeset:table (:col-widths '(100 430) :border 0)
>                     (typeset:row ()
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "Name"))
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "Erik Enge")))
>                     (typeset:row ()
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "Telephone"))
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "555-1234")))
>                     (typeset:row ()
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "Age"))
>                       (typeset:cell ()
>                         (typeset:paragraph ()
>                           "25")))))))
>            (typeset::draw-block content 20 800 545 700 0))))
>      (pdf:write-document file)))
>
> Can someone show me how I would turn that code into code that would
> essentially do the
> same thing for a list of objects, as described at the top of the mail?
> I have read typo.lisp
> and tables.lisp but there doesn't seem to be a functional equivalent to
> the table macro.

Why do you want a functional interface ?
It works directly with the macros:
You can even put the loop into a separate defun and it with work thanks to
the special var bindings :)

(defun testpdf (&optional (file #P"/tmp/test.pdf"))
  (pdf:with-document ()
    (pdf:with-page ()
      (pdf:with-outline-level ("Example" (pdf:register-page-reference))
 (pdf:set-line-width 0.1)
 (let ((content
        (typeset::compile-text ()
                  (typeset:paragraph (:font "Helvetica-Bold" :font-size 16)
         "Test document")
                  (typeset:hrule :dy 2)
                  (typeset:table (:col-widths '(100 430) :border 0)
      (loop for (name tel age) in '(("Erik Enge" "555-1234" "25")
        ("Erik Enge" "555-1234" "25")
        ("Erik Enge" "555-1234" "25")
        ("Erik Enge" "555-1234" "25")
        ("Erik Enge" "555-1234" "25"))
     do
                          (typeset:row ()
                            (typeset:cell ()
                              (typeset:paragraph ()
                                "Name"))
                            (typeset:cell ()
                              (typeset:paragraph ()
                                name)))
                          (typeset:row ()
                            (typeset:cell ()
                              (typeset:paragraph ()
                                "Telephone"))
                            (typeset:cell ()
                              (typeset:paragraph ()
                                tel)))
                          (typeset:row ()
                            (typeset:cell ()
                              (typeset:paragraph ()
                                "Age"))
                            (typeset:cell ()
                              (typeset:paragraph ()
                                age))))))))
           (typeset::draw-block content 20 800 545 700 0))))
     (pdf:write-document file)))

Marc





More information about the cl-typesetting-devel mailing list