Appending pdf documents into one

G

Guest

Here is what I am trying to do:
Open a.pdf, append b.pdf to it and save the aggregate as
c.pdf.
I want to do it through a program written in .net. I would like to do this
without using any tools or thirdparty components.
What i am trying out is getting the byte stream of the both the documents
and then merging the stream and getting one stream.

Any quick help will be appreciated.

Ganesh
 
B

bcutting

Don't know if you can do this by simply appending one stream to the
other. I believe there are headers and other elements in the PDF that
cannot be combined like this. There is a free library called pdflib
that could probably do it for you.
 
K

Kevin Frey

Appending byte streams together definitely will not work. PDF documents have
a header and a trailer, for one, that is singular to the whole document, so
concatenating two files together immediately violates this requirement. The
atomic pieces of a PDF document are called objects and they are uniquely and
sequentially numbered, such that the trailer of the PDF file refers to the
physical position within the file (ie. from offset 0) of each such object.

Clearly this structure is not going to work merely by concatenation. I'm
sure you could write a .NET class to do the merging, but it will be
extremely difficult. You will need to parse the files, read all the objects
into [probably] memory, find all the object references (objects can
reference other objects), then resequence all the objects so they have
unique numbers, and finally rewrite a new file. Because objects reference
other objects, you need to "understand" the structure of these objects in
order to identify the object references, and there are an incredible number
of different object types.

There are several products that will do PDF file merging - unless you have
weeks to months spare to roll your own, you might find an off-the-shelf
product that will do the job. PDFlib is one but from memory it is
horrendously expensive - I have seen other products which perhaps don't
necessarily offer the same capabilities but are virtually an order of
magnitude cheaper.

Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top