CL-PDF 0.3 (The Common Lisp PDF Library) 
Author Message
 CL-PDF 0.3 (The Common Lisp PDF Library)

02 February 2002: Release 0.3
   removed the use of keywords as PDF names
   cleaned up the code, put back write-line, removed gensym, etc.
   added a maze generation example

Here is what you get with the maze generation example:
(make-maze 53 80) gives the following pdf file
http://www.*-*-*.com/

Marc

*****************************************
CL-PDF is a Common Lisp PDF Library for generating PDF files.

You will find it here:
www.fractalconcept.com/asp/html/cl-pdf.html

It is released with a BSD style license so it's usable for commercial work.

It it how it looks:

(pdf:with-document ()
    (pdf:with-page ()
      (let ((helvetica (make-instance 'pdf:font)))
 (pdf:add-fonts-to-page helvetica)
 (pdf:in-text-mode
  (pdf:set-font helvetica 36.0)
  (pdf:move-text 100 800)
  (pdf:draw-text "cl-pdf: Example 1"))
 (pdf:translate 230 500)
 (loop repeat 101
       for i = 0.67 then (* i 1.045)
       do (pdf:in-text-mode
    (pdf:set-font helvetica i)
    (pdf:move-text (* i 3) 0)
    (pdf:draw-text "rotation"))
       (pdf:rotate 18))))
    (pdf:write-document file))

=> gives this > http://www.*-*-*.com/

Before writing it, I was rather impressed by the size of the PDF
documentation. After writing it I'm really impressed by Common Lisp. As you
will see, the library is quite small, yet really powerful.

So enjoy it and send me some great looking PDF files to put in a gallery on
the web site.

I also think that it's an opportunity to open several sub projects.

1) Finishing CL-PDF:

1.1- In CL-PDF I open the file for writing with a LW specific option to open
it with no CR/LF translation.
I would need the different versions of doing this on other implementation
running on Windows.

1.2-Compression : If someone would like to FLI the zlib compression, I could
integrate it to generate compressed PDF files. I can't do it alone as it has
to be done for several implementations to be useful.

2) Building utility layers on top of CL-PDF to turn it as a really powerful
drawing publication platform. I'm willing to coordinate and drive this
effort but I haven't the time to do it alone.

2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round rect,
etc.

2.2- Higher level Graphic functions. ie Functions to draw : axis, lin/log
scales, barcodes etc.
(OK all this exists but it's not always very good and does not always do
what you want.)

2.3-Text layout functions (well not a full Tex but at least writing text in
a box for instance)

2.4-CL-TeX: Well here I'm kidding but not completely ;-)

3) CL-PDF Logo like layer for kids. I have teach Logo at a local school
where my sons go but I've found that Logo was great to start but a deceptive
one after a while. A CL-PDF Logo could lead to extremely good quality
drawings. I definitively think that's a way to explore.

Feedback welcomed.

Marc



Thu, 22 Jul 2004 05:51:59 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)

Quote:

> 1.1- In CL-PDF I open the file for writing with a LW specific option to open
> it with no CR/LF translation.
> I would need the different versions of doing this on other implementation
> running on Windows.

You want to write the file with Unix style. Isn't
it?

In Clisp you could use:

(with-open-file (s filename :direction :output :if-exists :supersede :external-format :unix)
        ....

BTW, the generated file looks OK using
:external-format :default (with CR/LF) when viewed
using adobe acrobat reader. Is this convention
required by the PDF spec.?

Quote:
> 2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round rect,
> etc.

I'm a CL newbie and short of free time, but I have
a good background in geometry. Perhaps you could
crate a general design and I (or someone else)
could fill the implementation.

PD. Maybe we should move to private email?

--

Eduardo Mu?oz



Thu, 22 Jul 2004 20:09:32 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)


Quote:

> > 1.1- In CL-PDF I open the file for writing with a LW specific option to
open
> > it with no CR/LF translation.
> > I would need the different versions of doing this on other
implementation
> > running on Windows.

> You want to write the file with Unix style. Isn't
> it?

> In Clisp you could use:

> (with-open-file (s filename :direction :output :if-exists :supersede

:external-format :unix)

OK. :external-format is starndard but its values are implementation
dependent.

Quote:
> BTW, the generated file looks OK using
> :external-format :default (with CR/LF) when viewed
> using adobe acrobat reader. Is this convention
> required by the PDF spec.?

No you can use LF or CR/LF in PDF files but as the positions in the file are
absolute you have to be sure that the Lisp implementation does not convert
them when reading or writing the file to disk.

Quote:
> > 2.1-Basic Graphic primitives build on top of PDF : Arc, ellipse, round
rect,
> > etc.

> I'm a CL newbie and short of free time, but I have
> a good background in geometry. Perhaps you could
> crate a general design and I (or someone else)
> could fill the implementation.

For example PDF has only Bzier curves no arc nor circle. it would be useful
to have arcs functions that translate to Bzier curves. Same pb with
ellipical arc, ellipses etc.

For instance :
    circle center-x center-y radius
    ellipse center-x center-y radius-a radius-b rotation
    angle-arc center-x center-y radius start-angle sweep-angle
    angle-pie center-x center-y radius start-angle sweep-angle
    round-rect left-x bottom-y right-x top-y radius-x radius-y
    etc.

 > PD. Maybe we should move to private email?

As you want. I'm open to both email or c.l.l.

Marc



Thu, 22 Jul 2004 21:12:53 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)

Quote:



> > > 1.1- In CL-PDF I open the file for writing with a LW specific option to
> open
> > > it with no CR/LF translation.
> > > I would need the different versions of doing this on other
> implementation
> > > running on Windows.

> > You want to write the file with Unix style. Isn't
> > it?

> > In Clisp you could use:

> > (with-open-file (s filename :direction :output :if-exists :supersede
> :external-format :unix)

> OK. :external-format is starndard but its values are implementation
> dependent.

> > BTW, the generated file looks OK using
> > :external-format :default (with CR/LF) when viewed
> > using adobe acrobat reader. Is this convention
> > required by the PDF spec.?

> No you can use LF or CR/LF in PDF files but as the positions in the file are
> absolute you have to be sure that the Lisp implementation does not convert
> them when reading or writing the file to disk.

But why did it work in Acrobat Reader anyway, you ask?  Acrobat
quitely fixes up the xref table.  xpdf complains, and fixes it.
Ghostscript can't deal with it.

Quote:
>  > PD. Maybe we should move to private email?

> As you want. I'm open to both email or c.l.l.

I, for one, appreciate this discussion being on c.l.l.  I don't have
time to play with it right now, but when a need comes up (or I can
come up with a need for it) I plan on playing with it and maybe
contributing.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              



Fri, 23 Jul 2004 02:48:49 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)


Quote:

> > No you can use LF or CR/LF in PDF files but as the positions in the file
are
> > absolute you have to be sure that the Lisp implementation does not
convert
> > them when reading or writing the file to disk.

> But why did it work in Acrobat Reader anyway, you ask?  Acrobat
> quitely fixes up the xref table.  xpdf complains, and fixes it.
> Ghostscript can't deal with it.

This is why I need the :external-format value that will not translate CR/LF
to LF (and vice versa)  for every Common Lisp implementation working on
WinXXXX. I would then happily add the corresponding #+ to open the file.

So far I only have (:default :eol-style :lf) for LWW and :unix for CLISP

Quote:
> >  > PD. Maybe we should move to private email?

> > As you want. I'm open to both email or c.l.l.

> I, for one, appreciate this discussion being on c.l.l.  I don't have
> time to play with it right now, but when a need comes up (or I can
> come up with a need for it) I plan on playing with it and maybe
> contributing.

OK let's talk here....

Marc



Fri, 23 Jul 2004 05:01:27 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)

Quote:

> So far I only have (:default :eol-style :lf) for LWW and :unix for CLISP

I checked Corman Lisp. It will accept any value
and write the file in windows format anyway.

Quote:
> OK let's talk here....

Here we go  :)

The following code adds support for circles and
rounded rectangles. I welcome any suggestion since
I'm a newbie with CL. Any corrections to my
english are welcome too :)

Some comments. The quadrants stuff could be made
using pure geometry instead of these four
functions but IMHO it's too complicated (rotation
matrices) for the gain we would get.
I haven't added support for rotated elements by
now because you can handle rotation at a higer
level (pdf:rotate) and the things get messy very
quickly. Any curve has to be stroked and/or filled
with the page still rotated, so the function used
should be passed as a parameter.

(in-package pdf)

(defconstant +kappa+ (* 4 (/ (1- (sqrt 2.0)) 3)))

(defun first-quadrant (center-x center-y radius l-distance)
  (bezier-to (+ center-x radius) (+ center-y l-distance)
             (+ center-x l-distance) (+ center-y radius)
             center-x (+ center-y radius)))

(defun second-quadrant (center-x center-y radius l-distance)
  (bezier-to (- center-x l-distance) (+ center-y radius)
             (- center-x radius) (+ center-y l-distance)
             (- center-x radius) center-y))

(defun third-quadrant (center-x center-y radius l-distance)
  (bezier-to (- center-x radius) (- center-y l-distance)
             (- center-x l-distance) (- center-y radius)
             center-x (- center-y radius)))

(defun fourth-quadrant (center-x center-y radius l-distance)
  (bezier-to (+ center-x l-distance) (- center-y radius)
             (+ center-x radius) (- center-y l-distance)
             (+ center-x radius) center-y))

(defun circle (center-x center-y radius)
  ;; See http://www.whizkidtech.net/bezier/circle/
  ;; to know what are +kappa+ and l-distance
  (let ((l-distance (* radius +kappa+)))
    (move-to (+ center-x radius) center-y)
    (first-quadrant center-x center-y radius l-distance)
    (second-quadrant center-x center-y radius l-distance)
    (third-quadrant center-x center-y radius l-distance)
    (fourth-quadrant center-x center-y radius l-distance)))

(defun rectangle (x y dx dy &optional (radius 0))
  (cond ((eql radius 0)
         (format *page-stream* "~,3f ~,3f ~,3f ~,3f re~%" x y dx dy))
        (t
         (let ((l-distance (* radius +kappa+)))
           (move-to (+ x dx) (- (+ y dy) radius))
           (first-quadrant (- (+ x dx) radius) (- (+ y dy) radius)
                           radius l-distance)
           ;; Top line
           (line-to (+ x radius) (+ y dy))
           (second-quadrant (+ x radius) (- (+ y dy) radius)
                            radius l-distance)
           ;; Left line
           (line-to x (+ y radius))
           (third-quadrant (+ x radius) (+ y radius)
                           radius l-distance)
           ;; Bottom line
           (line-to (- (+ x dx) radius) y)
           (fourth-quadrant (- (+ x dx) radius) (+ y radius)
                            radius l-distance)
           ;;Right line
           (line-to (+ x dx) (- (+ y dy) radius))))))

;;; A sample pdf using this functions can be
;;; crated using this code.

(defun example6 (&optional (file #P"ex6.pdf"))
  (pdf:with-document ()
    (pdf:with-page ()
      (let ((helvetica (make-instance 'pdf:font)))
        (pdf:add-fonts-to-page helvetica)
        (pdf:in-text-mode
         (pdf:set-font helvetica 36.0)
         (pdf:move-text 100 800)
         (pdf:draw-text "cl-pdf: Example 6"))
        (pdf:set-rgb-stroke 0.1 0.1 0.8)
        (pdf:set-rgb-fill 0.8 0.5 0.1)
        (pdf:translate 50 400)
        (pdf:rectangle 100 250 100 100 0)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 300 250 100 100 10)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 100 100 100 100 20)
        (pdf:close-fill-and-stroke)
        (pdf:rectangle 300 100 100 100 40)
        (pdf:close-fill-and-stroke)
        (pdf:translate 200 -100)
        (loop repeat 100
              for i = 0.67 then (* i 1.045)
              do
              (pdf:set-rgb-fill (* 0.1 i) (* 0.01 i) (* 0.02 i))
              (pdf:circle (* i 3) 0 (* 1.5 i))
              (pdf:close-fill-and-stroke)
              (pdf:rotate 18))))
    (pdf:write-document file)))

--

Eduardo Mu?oz



Fri, 23 Jul 2004 06:52:09 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)


Quote:
> Here we go  :)

> The following code adds support for circles and
> rounded rectangles. I welcome any suggestion since
> I'm a newbie with CL. Any corrections to my
> english are welcome too :)

> Some comments. The quadrants stuff could be made
> using pure geometry instead of these four
> functions but IMHO it's too complicated (rotation
> matrices) for the gain we would get.
> I haven't added support for rotated elements by
> now because you can handle rotation at a higer
> level (pdf:rotate) and the things get messy very
> quickly. Any curve has to be stroked and/or filled
> with the page still rotated, so the function used
> should be passed as a parameter.

> (in-package pdf)

> (defconstant +kappa+ (* 4 (/ (1- (sqrt 2.0)) 3)))

> (defun first-quadrant (center-x center-y radius l-distance)
>   (bezier-to (+ center-x radius) (+ center-y l-distance)
>              (+ center-x l-distance) (+ center-y radius)
>              center-x (+ center-y radius)))

> (defun second-quadrant (center-x center-y radius l-distance)
>   (bezier-to (- center-x l-distance) (+ center-y radius)
>              (- center-x radius) (+ center-y l-distance)
>              (- center-x radius) center-y))

> (defun third-quadrant (center-x center-y radius l-distance)
>   (bezier-to (- center-x radius) (- center-y l-distance)
>              (- center-x l-distance) (- center-y radius)
>              center-x (- center-y radius)))

> (defun fourth-quadrant (center-x center-y radius l-distance)
>   (bezier-to (+ center-x l-distance) (- center-y radius)
>              (+ center-x radius) (- center-y l-distance)
>              (+ center-x radius) center-y))

> (defun circle (center-x center-y radius)
>   ;; See http://www.whizkidtech.net/bezier/circle/
>   ;; to know what are +kappa+ and l-distance
>   (let ((l-distance (* radius +kappa+)))
>     (move-to (+ center-x radius) center-y)
>     (first-quadrant center-x center-y radius l-distance)
>     (second-quadrant center-x center-y radius l-distance)
>     (third-quadrant center-x center-y radius l-distance)
>     (fourth-quadrant center-x center-y radius l-distance)))

> (defun rectangle (x y dx dy &optional (radius 0))
>   (cond ((eql radius 0)
>          (format *page-stream* "~,3f ~,3f ~,3f ~,3f re~%" x y dx dy))
>         (t
>          (let ((l-distance (* radius +kappa+)))
>            (move-to (+ x dx) (- (+ y dy) radius))
>            (first-quadrant (- (+ x dx) radius) (- (+ y dy) radius)
>                            radius l-distance)
>            ;; Top line
>            (line-to (+ x radius) (+ y dy))
>            (second-quadrant (+ x radius) (- (+ y dy) radius)
>                             radius l-distance)
>            ;; Left line
>            (line-to x (+ y radius))
>            (third-quadrant (+ x radius) (+ y radius)
>                            radius l-distance)
>            ;; Bottom line
>            (line-to (- (+ x dx) radius) y)
>            (fourth-quadrant (- (+ x dx) radius) (+ y radius)
>                             radius l-distance)
>            ;;Right line
>            (line-to (+ x dx) (- (+ y dy) radius))))))

As a style note, I generally use if when there is only one test condition +
then and else code.
Also I would use #'= 0 or #'ZEROP  instead of #'EQL
ie (if (zerop radius) ...

- Show quoted text -

Quote:
> ;;; A sample pdf using this functions can be
> ;;; crated using this code.

> (defun example6 (&optional (file #P"ex6.pdf"))
>   (pdf:with-document ()
>     (pdf:with-page ()
>       (let ((helvetica (make-instance 'pdf:font)))
> (pdf:add-fonts-to-page helvetica)
> (pdf:in-text-mode
> (pdf:set-font helvetica 36.0)
> (pdf:move-text 100 800)
> (pdf:draw-text "cl-pdf: Example 6"))
> (pdf:set-rgb-stroke 0.1 0.1 0.8)
>         (pdf:set-rgb-fill 0.8 0.5 0.1)
>         (pdf:translate 50 400)
>         (pdf:rectangle 100 250 100 100 0)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 300 250 100 100 10)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 100 100 100 100 20)
>         (pdf:close-fill-and-stroke)
>         (pdf:rectangle 300 100 100 100 40)
>         (pdf:close-fill-and-stroke)
> (pdf:translate 200 -100)
> (loop repeat 100
>       for i = 0.67 then (* i 1.045)
>       do
>               (pdf:set-rgb-fill (* 0.1 i) (* 0.01 i) (* 0.02 i))
>               (pdf:circle (* i 3) 0 (* 1.5 i))
>               (pdf:close-fill-and-stroke)
>       (pdf:rotate 18))))
>     (pdf:write-document file)))

I've put the example here:
http://www.fractalconcept.com/fcweb/download/ex6.pdf

Good Start!

Thanks,

BTW a zlib FLI is also on the way.

Marc



Fri, 23 Jul 2004 16:37:21 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)
On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"

Quote:

>OK. :external-format is starndard but its values are implementation
>dependent.

I have tested your code (v. 0.21) in MCL, and had to comment out the
:external-format keyword arg. Apart from that, it worked out of the
box. Nicely done!

- Paul

____________________________________________
Paul Meurer at HIT UiB no                                  
Humanities Information Technologies Centre,
University of Bergen
Allgaten 27, 5007 Bergen
Norway



Fri, 23 Jul 2004 16:46:01 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)


Quote:
> On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"

> >OK. :external-format is starndard but its values are implementation
> >dependent.

> I have tested your code (v. 0.21) in MCL, and had to comment out the
> :external-format keyword arg.

OK. Does MCL define a :mcl feature ?

Quote:
>Apart from that, it worked out of the
> box. Nicely done!

Thanks.

Marc



Fri, 23 Jul 2004 17:41:26 GMT  
 CL-PDF 0.3 (The Common Lisp PDF Library)


Quote:


> > On Sun, 3 Feb 2002 14:12:53 +0100, "Marc Battyani"

> > >OK. :external-format is starndard but its values are implementation
> > >dependent.

> > I have tested your code (v. 0.21) in MCL, and had to comment out the
> > :external-format keyword arg.

> OK. Does MCL define a :mcl feature ?

Not nedeed anymore. I now put :default by default, so I only need the
external-format values for the Lisp implementations which need something
different
from :default

Marc



Fri, 23 Jul 2004 18:12:19 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. CL-PDF the Common Lisp PDF Library 0.2

2. CL-PDF 0.45 (The Common Lisp PDF Library)

3. CL-PDF 0.41 (The Common Lisp PDF Library)

4. CL-PDF (Common Lisp PDF library) beta test

5. CL-PDF: need beta testers for cl-pdf 1.0

6. Common Lisp, the Langauge in PDF form?

7. Search some String in PDF with PDF.OCX

8. Appendix.pdf - Appendix.pdf (0/6)

9. extract info from pdf doc,PDF to XML, HTML

10. Acrobat 3.0 PDF Version of Tcl/Tk 8.0 Quick Reference - refbase.pdf (1/1)

11. Acrobat 3.0 PDF Version of Tcl/Tk 8.0 Quick Reference - refbase.pdf (0/1)

12. CL-AWK (Common Lisp AWK library)

 

 
Powered by phpBB® Forum Software