Inaimathi
Inaimathi

Reputation: 14065

cl-pdf output error

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.

Upvotes: 4

Views: 712

Answers (2)

Inaimathi
Inaimathi

Reputation: 14065

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.

Upvotes: 1

Xach
Xach

Reputation: 11839

(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.

Upvotes: 4

Related Questions