title: Adding bookmark to merged PDF's using pyPDF2
body: <p>I need to add bookmark to the new merged created pdf. I use a script that merge all pdfs from the curent directory using pyPDF2. I will be good to have bookmark structured with the name of the each pdf's. Each PDF it may have 1-2-3 pages.</p>
  
  <p>Code that's working for merging all pdf's from directory:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  from argparse import ArgumentParser
  from glob import glob
  from PyPDF2 import PdfFileReader, PdfFileWriter
  import os
  def merge(path, output_filename):
      output = PdfFileWriter()
      for pdffile in glob(path + os.sep + '*.pdf'):
          if pdffile == output_filename:
              continue
          print("Se adauga '%s'" % pdffile)
          document = PdfFileReader(open(pdffile, 'rb'))
          for i in range(document.getNumPages()):
              output.addPage(document.getPage(i))
  
      print("S-a creat pdf '%s'" % output_filename)
      with open(output_filename, "wb") as f:
                  output.write(f)
  if __name__ == "__main__":
      parser = ArgumentParser()
      # Add more options if you like
      parser.add_argument("-o", "--output",
                          dest="output_filename",
                          default="Test.pdf",
                          help="write merged PDF to FILE",
                          metavar="FILE")
      parser.add_argument("-p", "--path",
                          dest="path",
                          default=".",
                          help="path of source PDF files")
      args = parser.parse_args()
      merge(args.path, args.output_filename)
  </code></pre>