Merge PDF's with PDFTK with Bookmarks?

前端 未结 11 991
遥遥无期
遥遥无期 2020-12-04 08:51

Using pdftk to merge multiple pdf\'s is working well. However, any easy way to make a bookmark for each pdf merged?

I don\'t see anything on the pdftk docs regardin

11条回答
  •  没有蜡笔的小新
    2020-12-04 09:49

    The following is intended to be a comment to the answer by pdfmerger (https://stackoverflow.com/a/30524828/3915004).

    Thanks for your script pdfmerger! I know the question is marked linux, but to generalize your script for Mac OS X, 2 things are needed:

    • ghostscript gs and
    • the command pdfinfo (which is included e.g. in poppler)

    Install them by getting first brew (google it, it is installed via some curl/ruby-magic command ^^ ) and then simply:

    brew install ghostscript
    brew install poppler
    

    ADD-ON: READ TEXT-FILE WITH CHAPTER TITLES:

    To expand on your script. I use this workflow mainly for books available as chapter-downloads from the editors website. A textfile containing the chapter names can easily be generated. The following add-on to your code reads additionally a textfile 'chapters.txt' containing one line per pdf to merge. (Note, I didn't implement any check on the number of lines corresponding to the number of pdfs.)

    Simply expand your script by replacing the following lines:

    p = subprocess.Popen('ls *pdf', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    c = subprocess.Popen('less chapters.txt', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    
    pdfdateien = []
    kombinationen = []
    chapternames = []
    
    for line in c.stdout.readlines():
    # c contains all chapter-titles
      chapternames.append(line)
    
    for line in p.stdout.readlines():
    

    and

    for index, kombination in enumerate(kombinationen):
    #  dateiname = kombination[0][0:len(kombination[0])-5]
    #
    # Hier noch dateiname evtl. verwursten
    # z. B.
    #  lesezeichen = dateiname[0:1]+" "+dateiname[6:8]+"/"+dateiname[1:5]
    #  lesezeichen = dateiname
      lesezeichen=chapternames[index][:-1]
    
      anz_seiten = kombination[1][16:len(kombination[1])-1]
    

提交回复
热议问题