[cl-pdf-devel] Question about tables
Marc Battyani
marc.battyani at fractalconcept.com
Tue May 31 16:41:44 UTC 2005
"Peter Seibel" <peter at gigamonkeys.com> writes:
> [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've put the cl-typesetting mailing list in copy.
> 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))
There is the cell-padding also. Have you counted it ?
> 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?
For 2 and 3, the problem is probably that each cell is is a cl-typesetting
engine and the "parent" style is not passed to the cells (yet...). If you
wrap your cell's put-string into a with-style, it looks ok for me.
Marc
More information about the cl-pdf-devel
mailing list