Hello all,
A while ago I posted a little demo project that merges pdf files and adds bookmarks to the merged output file using PDFBox (see this thread http://www.vbforums.com/showthread.php?t=462929 ). However, when I recently started to use iTextSharp for manipulating Pdfs, I found a better way of merging pdfs and adding bookmarks to it using iTextSharp. These are a few advantages I found:
1. iTextSharp.dll is small (only 2.3 MB vs PDFBox's 16MB)
2. iTextSharp is significantly faster for manipulating pdf documents
3. Can add bookmarks while merging using itextSharp (with PDFBox, I first had to merge the files to a temp location, then reopen it to add bookmarks, then save it to the final location, then delete the temp file... pheeewww, too much work!)
4. You can fill in from here
5. ???
6. ???

All in all, I highly recommend using iTextSharp over PDFBox.

And here it is, the pdf merging function that utilizes iTextSharp libray. Just remember to add a reference to itextsharp.dll in your project if you this function. (You can google for download locations of iTextSharp if you don't already have it)

vb Code:
  1. Public Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String) As Boolean
  2.         Dim result As Boolean = False
  3.         Dim pdfCount As Integer = 0     'total input pdf file count
  4.         Dim f As Integer = 0            'pointer to current input pdf file
  5.         Dim fileName As String = String.Empty   'current input pdf filename
  6.         Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
  7.         Dim pageCount As Integer = 0    'cureent input pdf page count
  8.         Dim pdfDoc As iTextSharp.text.Document = Nothing    'the output pdf document
  9.         Dim writer As PdfWriter = Nothing
  10.         Dim cb As PdfContentByte = Nothing
  11.         'Declare a variable to hold the imported pages
  12.         Dim page As PdfImportedPage = Nothing
  13.         Dim rotation As Integer = 0
  14.         'Declare a font to used for the bookmarks
  15.         Dim bookmarkFont As iTextSharp.text.Font = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, _
  16.                                                                   12, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLUE)
  17.         Try
  18.             pdfCount = pdfFiles.Length
  19.             If pdfCount > 1 Then
  20.                 'Open the 1st pad using PdfReader object
  21.                 fileName = pdfFiles(f)
  22.                 reader = New iTextSharp.text.pdf.PdfReader(fileName)
  23.                 'Get page count
  24.                 pageCount = reader.NumberOfPages
  25.                 'Instantiate an new instance of pdf document and set its margins. This will be the output pdf.
  26.                 'NOTE: bookmarks will be added at the 1st page of very original pdf file using its filename. The location
  27.                 'of this bookmark will be placed at the upper left hand corner of the document. So you'll need to adjust
  28.                 'the margin left and margin top values such that the bookmark won't overlay on the merged pdf page. The
  29.                 'unit used is "points" (72 points = 1 inch), thus in this example, the bookmarks' location is at 1/4 inch from
  30.                 'left and 1/4 inch from top of the page.
  31.                 pdfDoc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
  32.                 'Instantiate a PdfWriter that listens to the pdf document
  33.                 writer = PdfWriter.GetInstance(pdfDoc, New IO.FileStream(outputPath, IO.FileMode.Create))
  34.                 'Set metadata and open the document
  35.                 With pdfDoc
  36.                     .AddAuthor("Your name here")
  37.                     .AddCreationDate()
  38.                     .AddCreator("Your program name here")
  39.                     .AddSubject("Whatever subject you want to give it")
  40.                     'Use the filename as the title... You can give it any title of course.
  41.                     .AddTitle(IO.Path.GetFileNameWithoutExtension(outputPath))
  42.                     'Add keywords, whatever keywords you want to attach to it
  43.                     .AddKeywords("Report, Merged PDF, " & IO.Path.GetFileName(outputPath))
  44.                     .Open()
  45.                 End With
  46.                 'Instantiate a PdfContentByte object
  47.                 cb = writer.DirectContent
  48.                 'Now loop thru the input pdfs
  49.                 While f < pdfCount
  50.                     'Declare a page counter variable
  51.                     Dim i As Integer = 0
  52.                     'Loop thru the current input pdf's pages starting at page 1
  53.                     While i < pageCount
  54.                         i += 1
  55.                         'Get the input page size
  56.                         pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i))
  57.                         'Create a new page on the output document
  58.                         pdfDoc.NewPage()
  59.                         'If it is the 1st page, we add bookmarks to the page
  60.                         If i = 1 Then
  61.                             'First create a paragraph using the filename as the heading
  62.                             Dim para As New iTextSharp.text.Paragraph(IO.Path.GetFileName(fileName).ToUpper(), bookmarkFont)
  63.                             'Then create a chapter from the above paragraph
  64.                             Dim chpter As New iTextSharp.text.Chapter(para, f + 1)
  65.                             'Finally add the chapter to the document
  66.                             pdfDoc.Add(chpter)
  67.                         End If
  68.                         'Now we get the imported page
  69.                         page = writer.GetImportedPage(reader, i)
  70.                         'Read the imported page's rotation
  71.                         rotation = reader.GetPageRotation(i)
  72.                         'Then add the imported page to the PdfContentByte object as a template based on the page's rotation
  73.                         If rotation = 90 Then
  74.                             cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)
  75.                         ElseIf rotation = 270 Then
  76.                             cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)
  77.                         Else
  78.                             cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
  79.                         End If
  80.                     End While
  81.                     'Increment f and read the next input pdf file
  82.                     f += 1
  83.                     If f < pdfCount Then
  84.                         fileName = pdfFiles(f)
  85.                         reader = New iTextSharp.text.pdf.PdfReader(fileName)
  86.                         pageCount = reader.NumberOfPages
  87.                     End If
  88.                 End While
  89.                 'When all done, we close the documwent so that the pdfwriter object can write it to the output file
  90.                 pdfDoc.Close()
  91.                 result = True
  92.             End If
  93.         Catch ex As Exception
  94.             Throw New Exception(ex.Message)
  95.         End Try    
  96.         Return result
  97.     End Function