bkmk4pdftk
While pdftk is great at adding bookmarks to a pdf, many (including me) find it's format tedious. This project tries to generate a pdftk format bookmark file from a table in google sheets using GAS (Google Sheet Scripts). Simply recreate the table of contents in one tab, run a script, and bam, you can download the pdftk file to add onto your pdf.
Basically the polar opposite of this. With Google Sheets (cause idk vba and I suck as a coder).
What does it do?
I find it easier to copy the Table of Contents from a pdf by Alt + Click -> Drag to select the text and copying it on a table. Then, use the macro to gather the data and export it to a pdftk bookmark formatted text file. See gif below for what this macro does.
How to Use It?
- Click on this link to view and duplicate the spreadsheet with the macro scripts.
Or follow these instructions to create your own spreadsheet with the GAS.
Create a **new** Google spreadsheet, click Tools > Script editor... then copy and paste the contents of the interday.gs file (see above) into the script editor and save. Return to the spreadsheet and refresh the page (Note: actually click the refresh button or select it from the menu; the keyboard shortcut is overridden on Google Sheets, at least in Google Chrome). A couple seconds after the page reloads you should see a "Menu" menu at the top.- Input your data to the table manually. Just copy and paste the page number, title into the table. Adjust the level as you see fit.
- Click on Menu and then dataToText. This function will gather the data in each row and appends the data into pdftk format text.
- Goto the
bookmark_input
tab and check things look good. If not, you can always change the values in the table and run the dataToText again. - Click on Menu and then ExportToTextFile. This function will convert the blocks of text on
bookmark_output
into a text file for download or copy pasting. - See below on how to use this text file for pdftk or pdfWriteBookmarks to add bookmarks onto your pdf.
How do I add bookmarks to my pdf from start to finish?
I'm sure those those who are reading this already know what pdftk is. But in cause you don't, pdftk is a tool kit that helps you add bookmarks to your pdf. If you have adobe acrobat, I really question why you are here. But if you are poor like me, then welcome to the club!
- Create you own spreadsheet by Clicking this link and duplicating it so you can enter your own data.
- Once you are done, click to start the macros and download the text file.
- Get pdftk here.
- Put your pdf file and your text file in the same folder. Start a command prompt in that folder path and enter the following code:
pdftk [input_file.pdf] update_info [bookmarks.txt] output [output_file.pdf]
For more info, read this. - A good alternative to using pdftk is pdfWriteBookmarks. Usage:
java -jar pdfWriteBookmarks.jar [input_file.pdf] [bookmarks.txt] [output.pdf]
- Done!
Todo
- Add page offset function the google sheet in case pasted page number is not the actual page number in the pdf.
- Make the same sheet w/ macros in Excel using VBA