I have a lot of articles that I've written that I want to assemble into one or more ebooks.
I can easily format each as a PDF file, but I don't know what software to use to merge them all, in the correct order, and at the same time create a table of contents that updates every time I add a new file.
-HankFriedman
Hi Hank. This might help, but only if you with ebook had in mind a merged .pdf file rather than .epub (reflowing text).
I updated an older autohotkey script of mine. It now uses pdftk to merge many pdf files to one big pdf with one bookmark per component pdf file. the order is set in a plain txt file so it is easy to add/rearrange.
;PdfMergeMark (by nod5 version 160924)
;Merge (concatenate, join) pdf files and add bookmarks
;How to use:
;1 Install PDFtk Server for Windows, https://www.pdflabs.com/tools/pdftk-server/
;2 Create pdflist.txt in same folder as PdfMergeMark.ahk
;3 Add one pdf file path per line, in the order you want. Save.
;4 Run PdfMergeMark.ahk --> outputs yyyymmddhhmmss.pdf
;pdflist.txt example:
;C:\test\file name.pdf
;C:\folder\another.pdf
;C:\some other folder\this file.pdf
;optional: custom path to pdftk
pdftk =
pdftk = C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe
p := 1
Loop, Read
, %A_ScriptDir%\pdflist
.txt
{
tooltip, Reading
... %A_LoopReadLine% runwait %comspec% /c
""%pdftk%" "%A_LoopReadLine%" dump_data | clip",,hide
bm .= "`nBookmarkBegin"
bm .= "`nBookmarkTitle: " noext
bm .= "`nBookmarkLevel: 1"
bm .= "`nBookmarkPageNumber: " p
p := p + pages1
}
runwait "%pdftk%" %pdfstring% cat output
"%out%_temp",,hide
;concatenate pdfs runwait "%pdftk%" A
="%out%_temp" cat A1
-end output
"%out%_temp2",,hide
;del old bookmarks runwait "%pdftk%" "%out%_temp2" update_info
"%out%_txt" output
"%out%",,hide
;new bookmarks
The pdflist.txt can be created and edited in Notepad. Put the path of each pdf file to merge in the order you want.
C:\test\file name.pdf
C:\folder\another.pdf
C:\some other folder\this file.pdf
Some limitations:
All bookmarks are on the same level, in other words no tree view of bookmarks (chapter 1, 1.1, ...)
No bookmark numbering (unless the user adds numbers to the filenames)
May fail if pdflist is very, very long (when exceeding maximum line string length for cmd)
I might add some more stuff later on and make a small NANY release out of it.