Skip to content
/ tocPDF Public

Generates bookmarks from the table of contents already available at the beginning of pdf files.

Notifications You must be signed in to change notification settings

aminya/tocPDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tocPDF

by Amin Yahyaabadi

Generates bookmarks from the table of contents already available at the beginning of pdf files.

The plan is to automate the whole procedure (https://github.com/aminya/tocPDF#automated).

Until then here is the manual procedure:

Manual:

Step 1: Extraction of toc pages from PDF:

Use Chrome or software that you already have to extract the pages that contain the table of contents.

Tutorial for extracting pages using Chrome https://www.techadvisor.co.uk/how-to/software/how-extract-pages-from-pdf-3679232/

We refer to this file as tocPDF.

Step 2: Extract table of contents text

Here we extract the text from tocPDF.

Even if your pdf file is searchable, usually when you copy the text the result is not in proper format (like a table).

Preferred Methods:

  • Tabula technology

For searchable PDF only - https://tabula.technology/

* Download and run the software
* Select table of contents and do this for each page
* Hit preview and export extracted data
* Export to csv format
  • Using OCR.space

for both scanned and searchable PDF - https://ocr.space/

* Upload tocPDF
* Check "Do receipt scanning and/or table recognition" option
* Use "Just extract text and show overlay (fastest option)" option.
* download or copy paste the generated text.

We refer to the generated text as tocText.

For the following steps, instead, you can check the following which does a similar thing but with a GUI

https://github.com/ifnoelse/pdf-bookmark/blob/master/README-EN.md

Step 3: Preparing the text of the table of content

Open tocText (txt or csv) with a spreadsheet editor (MS Excel or Google Sheet) or using a text editor.

Edit the text such that each page number is at the beginning of a line, e.g.

1 Cover
2 Table of Contents
5 Chapter 1
+6 Subchapter1
++7 Sub-Subchapter1
25 Chapter 2

Don't forget to add the offset to page number (usually the page numbers in pdf have an offset compared to printed document).

Step 4: Download k2pdfoptdoes:

http://willus.com/k2pdfopt/download/

Step 5: (only for Windows) Disabling the GUI :

Disabling the GUI using this tutorial http://willus.com/k2pdfopt/help/nogui.shtml

Then drag the original pdf file into your shortcut.

Step 6: Run the command:

Windows:

copy toc.txt and source pdf file in the folder of your shortcut for convenience.

Copy-paste the following command in the terminal and press enter.

-mode copy -n -toclist toc.txt srcfile.pdf -o outfile.pdf

Press enter again to start bookmarking.

OSX or Linux:

k2pdfopt -mode copy -n -toclist toc.txt srcfile.pdf -o outfile.pdf

Other Manual Methods:

Other method using Jpdfbookmark

https://sourceforge.net/projects/jpdfbookmarks/

from https://ebooks.stackexchange.com/a/7763/12921

Prepare the tocText file such that

Chapter 1. The Beginning/23
    Para 1.1 Child of The Beginning/25,FitWidth,96
        Para 1.1.1 Child of Child of The Beginning/26,FitHeight,43
Chapter 2. The Continue/30,TopLeft,120,42
    Para 2.1 Child of The Beginning/32,FitPage

You can OCR the TOC and use regex to fix it.

Load that TOC

Expand all bookmarks (Ctrl + E), select all of them, then go to Tools > Apply Page Offset

Enter the first pages that outmatch the page number in the TOC

You can read its manual (http://jpdfbookmarks.altervista.org/InsertBookmarks.html#1_3_1) or watch a quick video tutorial (https://youtu.be/7DUkvH7_wII?t=30). It has command line mode and can work on Linux, Mac.

Other Methods for step 2:

References:

https://www.willus.com/k2pdfopt/help/k2menu.shtml

https://www.willus.com/k2pdfopt/help/options.shtml

https://ebooks.stackexchange.com/questions/107/how-to-create-clickable-table-of-contents-in-a-pdf

About

Generates bookmarks from the table of contents already available at the beginning of pdf files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published