How do I merge two PDFs by merging corresponding pages together?

Q: I have 2 PDF, both with N pages. I want to generate a 3rd PDF in
which the 1st page has the background of the 1st page of the 1st PDF
and the foreground is the 1st page of the 2nd PDF, and so on for the N
pages. Is it possible with PDFNet SDK (
A: With PDFNet it is fairly easy to place one PDF page on top or
behing another page. The code would look along the following lines
(assuming you are using C# - other languages are similar):


using (PDFDoc doc1 = new PDFDoc("in1.pdf")) {

// Import pages from doc2 into doc1.
ArrayList imported_pages = null;
using (PDFDoc doc2 = new PDFDoc("in2.pdf")) {
   ArrayList import_list = new ArrayList();
   for (PageIterator itr = doc2.GetPageIterator(); itr.HasNext();
   imported_pages = doc1.ImportPages(import_list);

// Place imported pages onto existing pages in doc1
using (ElementBuilder b = new ElementBuilder()) {
  using (ElementWriter w = new ElementWriter()) {
   PageIterator itr = doc1.GetPageIterator();
   for (int i=0; i<imported_pages.Count && itr.HasNext(); ++i,
itr.Next()) {
    w.Begin(itr.Current(), ElementWriter.WriteMode.e_overlay);
    Page pg = (Page)imported_pages[i];
    Element element = b.CreateForm(pg);
    element.GetGState().SetTransform(pg.GetPageWidth(), 0, 0,
pg.GetPageHeight(), 0, 0);
doc.Save("out.pdf", 0);

For a relevant code you may want to take a look at ImpositionTest
sample project:

Q: Is it possible to use your PDFTron PDFNet SDK (http:// product in order to take certain pages from
one PDF-file and certain pages from another PDF-file and super impose
one page over the other whilst still retaining the layer information?
In other words not have the resulting PDF-file have just one layer
with the old layer data converted into illustrator group objects
(layers from original files put into one single layer).

If this is possible, could you perhaps show an example of how I can
test this out in Java or C? (or refer me to some online material that
might explain this)

A: You can use PDFNet to implement the required functionality. For a

relevant code you may want to take a look at ImpositionTest sample

project: as
well as LayersTest.

In case you are working with OCG-s depending on your merging
requirements you may need to configure the OCG array in document’s OCG
configuration (i.e. pdfdoc.GetOCGConfig()).

Since I’m a VB programmer can u send me the sample in VB?
A: The best starting point is ImpositionTest sample (http:// There is also a VB version of
this sample:

The main difference is that you would:

a) open an existing document instead of a new one:

Dim new_doc As PDFDoc = New PDFDoc
→ Dim new_doc As PDFDoc = New PDFDoc(“background.pdf”)

b) write to an existing page instead of the new one:

Dim new_page As Page = new_doc.PageCreate(media_box)
→ writer.Begin(new_doc.GetPage(i+1),

c) comment out the code which is placing the second page on the same
destination page.

’ Place the second page
i = i + 1
’ If i < imported_pages.Count Then
’ src_page = imported_pages(i)
’ …
’ i = i + 1
'End If