Hi all,
I'm wondering if anyone can point me in the right direction. We're
trying to find a way to manipulate PDF files in Lisp. Mainly, we need
to be able to "read" a PDF document, determine how many pages it
contains, be able to extract each page into a separate document, and
take a "snapshot" of a page into a .GIF/.TIFF/etc thumbnail file. Any
ideas?
Thanks,
Waldo
Waldo wrote:
> I'm wondering if anyone can point me in the right direction. We're
> trying to find a way to manipulate PDF files in Lisp. Mainly, we need
> to be able to "read" a PDF document, determine how many pages it
> contains, be able to extract each page into a separate document, and
> take a "snapshot" of a page into a .GIF/.TIFF/etc thumbnail file. Any
> ideas?
Its getting a little old, but cl-pdf[1] should do half of what you
want. Its got a pdf parser and such but I'm not sure about the the
thumbnail snapshots.
[1]: http://www.fractalconcept.com/asp/html/cl-pdf.html
The easiest way to achieve your goal might be to use ImageMagick. For
example, `convert x.pdf x.png` should dump one file per pdf page, each
named x.png.N. Probably best done with a mix of lisp and shell
scripting, but CL-Magick may help.
[2]: http://common-lisp.net/project/cl-magick/
- Daniel
On Nov 13, 3:08 am, D Herring <········@at.tentpost.dot.com> wrote:
> Waldo wrote:
> > I'm wondering if anyone can point me in the right direction. We're
> > trying to find a way to manipulate PDF files in Lisp. Mainly, we need
> > to be able to "read" a PDF document, determine how many pages it
> > contains, be able to extract each page into a separate document, and
> > take a "snapshot" of a page into a .GIF/.TIFF/etc thumbnail file. Any
> > ideas?
>
> Its getting a little old, but cl-pdf[1] should do half of what you
> want. Its got a pdf parser and such but I'm not sure about the the
> thumbnail snapshots.
>
> [1]:http://www.fractalconcept.com/asp/html/cl-pdf.html
>
> The easiest way to achieve your goal might be to use ImageMagick. For
> example, `convert x.pdf x.png` should dump one file per pdf page, each
> named x.png.N. Probably best done with a mix of lisp and shell
> scripting, but CL-Magick may help.
>
> [2]:http://common-lisp.net/project/cl-magick/
>
> - Daniel
Thanks. I had looked at cl-pdf but from looking and it, it seems to
only be able to "write" pdfs programmatically. Maybe I'm mistaken. I
like the ImageMagick approach. Will evaluate it.
Thanks again
Waldo <·····@infoway.net> writes:
> Thanks. I had looked at cl-pdf but from looking and it, it seems to
> only be able to "write" pdfs programmatically. Maybe I'm mistaken.
CL-PDF includes a parser that converts a PDF file to in-memory
structures. It isn't very high-level, and the functions to use it aren't
exported, but it works. See the end of pdf-parser.lisp for an example.
Zach
On Nov 12, 11:42 pm, Waldo <·····@infoway.net> wrote:
> Hi all,
>
> I'm wondering if anyone can point me in the right direction. We're
> trying to find a way to manipulate PDF files in Lisp. Mainly, we need
> to be able to "read" a PDF document, determine how many pages it
> contains, be able to extract each page into a separate document, and
> take a "snapshot" of a page into a .GIF/.TIFF/etc thumbnail file. Any
> ideas?
>
> Thanks,
> Waldo
Here it is in Clozure CL. I realize this is just thinly disguised
objective-c and dependent on Apple's PDFKit and Cocoa frameworks, but
what the heck...
(in-package :ccl)
(objc:load-framework "Quartz" :quartz)
(let* ((pdf-doc (#/initWithURL: (#/alloc (@class "PDFDocument"))
(#/fileURLWithPath: (@class "NSURL")
(%make-nsstring "somefile.pdf"))))
(image (#/initWithSize: (#/alloc ns:ns-image) (ns:make-ns-point
85 110))))
(loop for i from 0 to (- (#/pageCount pdf-doc) 1) do
(let ((page-rep (#/dataRepresentation (#/pageAtIndex: pdf-doc
i))))
(#/writeToFile:atomically: page-rep (%make-nsstring
(format nil "/tmp/output/page~d.pdf" i)) #$YES)
(#/lockFocus image)
(#/drawInRect: (#/imageRepWithData: ns:ns-pdf-image-rep page-
rep)
(ns:make-ns-rect 0 0 85 110))
(#/unlockFocus image)
(#/writeToFile:atomically: (#/TIFFRepresentation image)
(%make-nsstring (format nil "/tmp/output/page~d.tiff" i)) #
$YES)
)))