[cl-pdf-devel] Concatenating PDF files

Marc Battyani marc.battyani at fractalconcept.com
Mon Nov 14 20:58:28 UTC 2005


Edi Weitz <edi at agharta.de> wrote:

>I need to concatenate a couple of PDF files, i.e. if I have PDF A with
>10 pages, PDF B with 5 pages, and PDF C with 8 pages, then the
>resulting PDF should have 23 pages where page 1 is page 1 of PDF A,
>page 11 is page 1 of PDF B, and so on.  The pages are supposed to
>remain unchanged /except/ for the page numbers which should be updated
>accordingly.
>
>I talked about this briefly with Arthur Lemmens and he said that the
>part with the page numbers will probably be hard and that there's no
>general solution for it.  (I had naïvely assumed that the PDF format
>had some mechanism to abstract away page numbers like Word but now
>that I think of it this is most likely nonsense.)
>
>Nevertheless, at the moment I don't even know enough of CL-PDF to be
>able to concatenate the files without wading through the source code
>for a couple of hours.  So, if someone could provide me with some
>lines of example code to get me started I'd be /very/ thankful.

Indeed, a pdf file is just a bunch or recorded graphical commands. It has
lost all structure except for some meta information.

But it should work anyway! ;-)

Tim Daly Jr has sent the code for the transformation of pdf pages into
XObject, which can be printed on a page like any graphical element. (It's in
the current cl-pdf version, look at pdf-template.lisp) So you just have to
write the pages and then draw the new page numbers above the existing ones.
If it's on a plain background it's easy.

>I know about this tool
>
>  <http://thierry.schmit.free.fr/dev/mbtPdfAsm/enMbtPdfAsm2.html>
>
>but I'd rather do it all in Lisp if possible.

Sure.

>PS: Marc, Arthur is not in contributors.txt - I think he provided the
>    parser, didn't he?

Oops, thanks for pointing this. I'm very sorry Arthur :-(
I had a cl-yacc based parser but replaced it by Arthur's one which is nicer.
(Arthur is credited in the lisp file though)
This will show up in the next commit. I have to test and merge Dmitriy's
code before.

BTW if I've forgotten to mention other people, please tell it to me.

Cheers,

Marc





More information about the cl-pdf-devel mailing list