[cl-pdf-devel] Image storage emergency

Dave Cooper dave at genworks.com
Sat Dec 16 15:59:31 UTC 2006


Jonathon:

I think the answer to your question already there in your question :).
 Just add the image once to the document, _outside_ the scope of any
of the pages.

Here is a simple example (the image I am using is the jpeg image
linked below but this should be the same with png images and
make-png-image). With the example below, the resulting PDF file sizes
are as follows (this is with pdf:*compress-streams* as nil):

1 page: 46404
5 pages: 48564
50 pages: 72921
500 pages: 318589
1000 pages: 593590

and if you inspect the PDF file you will see that the image stream
data is only there once, near the beginning of the file, before any of
the "<< /Type /Page"



;;;;;;;;;;;;;

(defpackage :pdf-user (:use :cl :pdf))
(in-package :pdf-user)

(defun logo-pages (&key (pages 50))
  (pdf:with-document ()
    (let ((logo-image (make-jpeg-image "/tmp/dj001.jpg")))
      (dotimes (n pages)
        (with-page ()
          (translate 30 700)
          (let ((helvetica (get-font "Helvetica")))
            (in-text-mode
             (set-font helvetica 36.0)
             (draw-text (format nil "cl-pdf: Image Page ~a" n)))
            (add-images-to-page logo-image)
            (draw-image  logo-image 0 -500 545 409 0 t)))))
    (write-document "/tmp/logo-pages.pdf")))

;;;;;;;;;;;

Here's the link to the sample image I used:

http://f7.yahoofs.com/users/yVGXbR8p.DBo/__sr_/d2fa.jpg?tkn=phMKChFBFE1y15.x&saveas=dj001

 -dave


On 12/16/06, Jonathon McKitrick <jcm at freebsd-uk.eu.org> wrote:
> Hey guys,
>
> I'm having a bit of a crisis with images in pdf's.  We have a logo on every
> page, and I'm not sure how to add the image only once to the document.  The
> resulting pdf went from a few hundred K to 1.6M!  I've got to get this
> resolved ASAP.  Does anyone know how I can add a png to the pdf only once,
> then refer to it again on each page?
>
> Jonathon McKitrick
> --
> My other computer is your Windows box.
> _______________________________________________
> cl-pdf-devel site list
> cl-pdf-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/cl-pdf-devel
>


-- 
Dave Cooper
dave at genworks.com
248-932-2166(o), 248-330-2979(c),
1-800-731-9220(toll-free in North America)



More information about the cl-pdf-devel mailing list