[cl-pdf-devel] Question about tables

Peter Seibel peter at gigamonkeys.com
Tue May 31 15:44:29 UTC 2005


[This message got rejected by the cl-typesetting list--maybe I'm not
subscribed under this address to that list. Or did that list get
decomissioned? Anyway, I'm sure someone here can help too.]

I'm trying to make some PDF reports with a bunch of spreadsheet-style
tables. Here's some sample code:

  (defpackage :com.gigamonkeys.table-test (:use :cl :typeset))

  (in-package :com.gigamonkeys.table-test)

  (defun make-test-data (columns rows)
    (loop for c from 0 below columns
       collect
         (list
           (format nil "COLUMN ~d" c)
           (coerce (loop repeat rows collect (+ 10000 (random 10000d0))) 'vector))))

  (defun compute-column-widths (columns)
    (let ((cols (length columns)))
      (loop repeat cols collect (floor (- 792 (* 2 36)) cols))))

  (defun test-cell-wrapping (columns &optional (file "/tmp/analysis.pdf"))
    (with-document ()
      (let ((content
             (compile-text ()
               (paragraph (:h-align :center :font "Helvetica-Bold" :font-size 18 :color '(0.0 0 0.0)) "Test" :eol)
               (with-style (:font "Helvetica" :font-size 6)
                 (table (:col-widths (compute-column-widths columns) :splittable-p t)
                   (header-row ()
                     (loop for label in (mapcar #'first columns) 
                        do (cell () (with-style (:font "Helvetica-Bold") label))))

                   (loop for i from 0 below (length (second (first columns))) do
                        (row ()
                          (loop for col in (mapcar #'second columns)
                             do (cell () (put-string (format nil "~,2f" (aref col i)))))))))
               (vspace 10)
               :eol)))
        (draw-pages content :size :letter :orientation :landscape :margins '(36 36 36 36))
        (when pdf:*page* (finalize-page pdf:*page*))
        (pdf:write-document file))))

I have three main questions:

 1) Why doesn't my compute-column-widths work correctly--it seems that
    I'm taking the total width of the page, subtracting the width of
    the left and right margins and then dividing by the number of
    columns. Yet the table, while starting at what looks like the
    correct left margin, goes to or even beyond the right edge of the
    page. To see this try evaluating:

      (test-cell-wrapping (make-test-data 10 10))

 2) Why does the content of the cells get broken over two lines even
    when there's seemingly plenty of room left in the cell. To see
    what I'm talking about try:

     (test-cell-wrapping (make-test-data 15 10))

 3) How do I adjust the line height to make the height of the rows
    smaller?

-Peter

-- 
Peter Seibel                                     peter at gigamonkeys.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp



More information about the cl-pdf-devel mailing list