[cl-pdf-devel] embedding PDF

Marc Battyani marc.battyani at fractalconcept.com
Sun Feb 12 17:17:25 UTC 2012


On 2/12/2012 6:04 AM, Tamas Papp wrote:
> Hi,
>
> Is it possible to embed another PDF file (ie render it contents at a
> particular coordinate) in a document generated by CL-PDF?

pdf-templates.lisp has code to print pages extracted from a pdf to some
position/size on a new page. Here is the example from this file:

;;;## Example Usage
;;; Try something like this after loading pdf-template.lisp:
;;;
;;; (pdf:test-template "/tmp/ex7.pdf" 1 "/tmp/template.pdf")

(defun test-template (in-file page-number out-file)
  "Create a new PDF with the given file and page number drawn several
times.  This test requires pdf-parser to be loaded."
  (let* ((old-doc (read-pdf-file in-file))
         (old-root (root-page old-doc))
         (old-page (aref (pages old-root) page-number))
         (old-page-bounds (or (resolve-page-dict-value (content
old-page) "/MediaBox")
                              *default-template-size*))
         (width (svref old-page-bounds 2))
         (height (svref old-page-bounds 3)))
    (with-document ()
      (with-page (:bounds old-page-bounds)
        (let ((top-template (make-template-from-page
                             old-page :scale 2/5 :translate-x (* 3/10 width)
                             :translate-y (* 3/5 height)))
              (right-template (make-template-from-page
                               old-page :scale 2/5 :rotate 90
                               :translate-x (* 3/5 width) :translate-y
(* 3/10 height)))
              (left-template (make-template-from-page
                              old-page :scale 2/5 :rotate -90
                              :translate-y (* 3/10 height )))
              (bottom-template (make-template-from-page
                                old-page :scale 2/5 :rotate 180
                                :translate-x (* 3/10 width))))
          (add-templates-to-page top-template right-template
                                 left-template bottom-template)
          (draw-template top-template)
          (draw-template bottom-template)
          (draw-template left-template)
          (draw-template right-template)))
      (write-document out-file))))

Marc




More information about the cl-pdf-devel mailing list