4
votes

I'm trying to use cl-pdf for some fairly basic PDF generation, but I'm getting tripped up at the examples (which is embarassing to say the least).

When I run the first example included in the package

(defun example1 (&optional (file #P"/tmp/ex1.pdf"))
  (pdf:with-document ()
    (pdf:with-page ()
      (pdf:with-outline-level ("Example" (pdf:register-page-reference))
        (let ((helvetica (pdf:get-font "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 150
         for i = 0.67 then (* i 1.045)
         do (pdf:in-text-mode
             (pdf:set-font helvetica i)
             (pdf:set-rgb-fill (/ (random 255) 255.0)
                               (/ (random 255) 255.0)
                               (/ (random 255) 255.0))
             (pdf:move-text (* i 3) 0)
             (pdf:show-text "cl-typesetting"))
           (pdf:rotate 13)))))
    (pdf:write-document file)))

by running (example1 #P"/home/inaimathi/Desktop/ex1.pdf") it gives me this error

#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf" 
{CF9D931}> is not a binary output stream. 
    [Condition of type SIMPLE-TYPE-ERROR]

Restarts:
 0: [ABORT] Exit debugger, returning to top level.

The same thing happens when I call (example1), or when I do

(with-open-file 
     (test-file #P"/home/inaimathi/Desktop/ex1.pdf" 
     :direction :output :if-does-not-exist :create) 
   (example1 test-file))

Finally, if I try

(with-open-file 
     (test-file #P"/home/inaimathi/Desktop/ex1.pdf" 
     :direction :output :if-does-not-exist :create 
     :element-type '(unsigned-byte 8)) 
   (example1 test-file))

I get the error

#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf" 
{D197C99}> is not a character output stream.
   [Condition of type SIMPLE-TYPE-ERROR]

Restarts:
 0: [ABORT] Exit debugger, returning to top level.

Is there a way to declare a binary character stream? How do I get simple output out of cl-pdf? I'm using SBCL straight out of the debian repos (which is 1.0.29, I think), in case it matters.

2
I'm looking at my stuff (uses cl-typesetting, which calls cl-pdf's write-document) and it looks fine. Is it possible you're running into permissions problems?Frank Shearar
Doesn't seem to be a permission error; regular calls to with-open-file still succeed when I try to write to the same file as above, and I set the target directory to 777 earlier just to check if it helps. What CL implementation are you using, and what version of cl-pdf do you run? (I downloaded the "cl-pdf-current" tarball from the fractal concept site, not sure how current it is)Inaimathi
Sadly, the Debian repositories are not very up to date (almost no Linux distribution's CL repositories are, except the Gentoo Lisp overlay). I would recommend to get a current SBCL.Svante
Tried out the latest SBCL binary from their project page (which is 1.0.49), and it generated the same error when I tried to define and call example1; this is not a binary stream. So it's not (just) the version of SBCL.Inaimathi
I'm using SBCL, and my cl-pdf and cl-typesetting are from svn, dated 2009-08-07.Frank Shearar

2 Answers

4
votes

(setf pdf:*compress-streams* nil) should help. It's trying to write binary data to a character stream, and while that works on LispWorks and some other systems, it doesn't work everywhere and particularly not on SBCL.

1
votes

EDIT 2: asdf-install is unmaintained and deprecated. It is best to use Quicklisp. To install Quicklisp, you'll need to download it:

$ curl -O https://beta.quicklisp.org/quicklisp.lisp

Then add cl-pdf to your lisp installation:

$ sbcl --load quicklisp.lisp
* (quicklisp-quickstart:install)
* (ql:quickload "vecto")
* (ql:add-to-init-file)
* (exit)

Now all you need to do is add

(load "~/quicklisp/setup.lisp") ; if it installed in the default location

to your .lisp file, and you can then add

(ql:quickload "cl-pdf")

EDIT: This is what I ended up doing. The solution by xach above would also work.

In the end I had to wget http://www.fractalconcept.com/download/cl-pdf-current.tgz and install that.

For the newbs (since I remember how frustrating it is for someone new to Common Lisp to hear "just do a checkout and install it"):

1.Do the checkout as above (I assume you've done this in your home directory from now on)

2.Type in tar xvzf cl-pdf-current.tgz (the point is to get a tarball of the folder. You can do this through the GUI too, it makes no difference)

3.Hop into your SBCL prompt and enter

(require 'asdf)
(require 'asdf-install)

4.If you already installed cl-pdf using (asdf-install:install 'cl-pdf), then you'll need to enter (asdf-install:uninstall 'cl-pdf)

5.Type (asdf-install:install "/home/[your home folder name]/cl-pdf-current.tgz")

I got one compilation error throughout this process, which I just selected [Accept] for. It still seems to work fine.

Hopefully the upcoming release of quicklisp will reduce the need for this sort of package hunting.