30

I have many technical PDF ebooks where there are no chapters (no clickable table of contents or other means for quick navigation through a document) and therefore it's really painful to search for information without full-text search. How could I create them? I would like to just take a PDF book and generate exact structure of chapters and subchapters, like:

  1. Intro
  2. First chapter
    • Tools you will need
    • Tool XYZ
  3. Second chapter
  • As there are more than one option to edit PDFs (both free & paid), For Mac: Adobe Reader, PDF Expert could be useful options, For Windows: Foxit Reader, Xodo are possible options. You can learn almost everything about editing PDFs and many other possible PDF Editors via this guide to editing PDFs. – Erman Ergün Nov 6 '18 at 11:35

12 Answers 12

13

Well, you could always buy a copy of Adobe Acrobat, which is actually designed solely for the purpose of creating and editing PDF files.

Or you could import the file into Calibre, convert it to ePub format, edit the ePub to add the table of contents, then convert it back to PDF.

There are other free tools for working with PDF directly. If you do a Google search, you would find this page which lists several free tools for editing or modifying PDF in various ways.

| improve this answer | |
9

I have used jPdfBookmarks on both Windows and Linux to do exactly what you describe - create your own bookmarks. Find it here.

| improve this answer | |
  • This is my recommendation if you have a table of contents beforehand. See my full tutorial below – Ooker Jun 21 '18 at 1:52
8

I will extend on @Donald's answer but I would also like to note I do not recommend, personally for quality issues, ever using Calibre for ebook development.

As stated I would suggest getting a copy of Acrobat and you can (for this example I am using Acrobat X Standard but note the I have not seen any difference in the shortcut buttons BUT the GUI has changed since version 9):

  • Open the .pdf file in Acrobat

enter image description here

  • Select the bookmark tab on the left side

enter image description here

  • Create the bookmark (two different ways): By button enter image description here, or use shortcut Ctrl + B (windows) or Cmd + B (mac):

enter image description here

You can create bookmarks by dragging and dropping the sub-level bookmark onto the level 1 bookmark such as:

enter image description here

| improve this answer | |
  • A slightly cheaper alternative to Adobe Acrobat is Foxit's PhantomPDF. I use it at the office a lot to manipulate bookmarks in PDF documents. – Nathan Osman Dec 20 '13 at 5:20
8

k2pdfopt (free, open source) can also do this by supplying a text file. See the -toclist option. Use like so:

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

...where my_chapter_list.txt is a simple ASCII file with page numbers beginning each line, e.g.

1 Cover
2 Table of Contents
5 Chapter 1
25 Chapter 2
...
| improve this answer | |
  • Does this edit the PDF in any way other than adding the toc as metadata? – MattHusz Jun 12 at 18:01
7

There are also free tools that allow editing/adding bookmarks. A cross platform example is jPdf Tweak.

It is a little clumsy to use, but you can create the table of contents in your favourite spreadsheet program, export as csv and then just import it.

| improve this answer | |
  • 1
    I also have used jpdftweak, and it has served me quite well. Page numbers can be a bit confusing if you want them labeled i, ii, iii, iv, ... and then 1, 2, 3 ..., but it's worth taking the time to figure it out. – Diagon Aug 3 '19 at 12:42
3

Jpdfbookmark can work for scanned books

  1. Prepare the TOC in .txt file

    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.

  2. Load that TOC

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

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

Your can read its manual or watch a quick video tutorial. It has command line mode and can work on Linux, Mac.

| improve this answer | |
3

I am used to a simple and free tool that adds clickable bookmarks to PDF or DjVU files: http://handyoutlinerfo.sourceforge.net/.

You first have to prepare (and import in the tool) bookmarks entered in a text file as an indented list of labels and pages. Then the tool creates them in the document as bookmarks you can open/reduce and click on using the left panel.

There are some good options such as shifting all page numbers first with a given constant. This is useful when the prepared file is actually a copy/paste extract from the table of contents existing (but only as text and without bookmarks) in the document: as cover, preface, introduction, ... are generally numbered separately.

| improve this answer | |
  • Welcome to SE-ebooks. You may note that this is an older question, so that reactions may be less. Nevertheless, answering older questions is encouraged when it provides new data or knowledge. – babou Sep 27 '18 at 10:58
2

THIS PART IS EDITED

For 'software-generated' PDF-files, i.e. PDF's not created from scans, I recommend to use (and upvote the answer by Krasjet) pdf.tocgen. Using this package becomes even easier with the toc-mode package for (Spac)Emacs described next.

For all other PDF and DJVU documents there is a new package called toc-mode for Emacs, which in my opinion provides the easiest way to add Table of Contents to documents (for linux and possibly also for different OS's). It includes options to extract the TOC via OCR.

In case this package's functionality is not sufficient or using Emacs is no option then the remaining part of this answer remains valid.

END EDITED PART

(Not enough reputation points to comment) Like the answer by Patrick Bourdon, I would also recommend HandyOutliner (http://handyoutlinerfo.sourceforge.net/). However, I would suggest you try the python script called document-contents-extractor to extract the contents.

If these options do not work, then I would also like to recommend PDF-XChange Viewer as a very powerful bookmark/contents extractor (selected text can be easily added to the bookmarks). It works well under wine.

Although not related to the question, I just would like to add that at the moment PDF X-Change viewer appears to me to be the most powerful PDF editor/viewer on linux. (although Emacs's amazing PDF-tools and Zathura are my favorite PDF editor and viewer respectively).

| improve this answer | |
1

WPS office suite on Windows allows creating or editing pdf's TOC

Be aware that it's a bit invasive though (shortcuts, default, runs in background...)

| improve this answer | |
1

I wrote an open source command line toolset called pdf.tocgen just for doing this. It uses the embedded font attributes and position information of headings to generate a table of contents automatically.

For example, for the PDF version Paul Graham's On Lisp, available for download on his website but comes without a table of contents. You could use the pdfxmeta tool to build a "recipe" file

[[heading]]
level = 1
font.name = "Times-Bold"
font.size = 19.92530059814453

[[heading]]
level = 2
font.name = "Times-Bold"
font.size = 11.9552001953125

save it as recipe.toml, and use the pdftocgen command to automatically generate an outline

$ pdftocgen onlisp.pdf < recipe.toml
"Preface" 5
    "Bottom-up Design" 5
    "Plan of the Book" 7
    "Examples" 9
    "Acknowledgements" 9
"Contents" 11
"The Extensible Language" 14
    "1.1 Design by Evolution" 14
    "1.2 Programming Bottom-Up" 16
    "1.3 Extensible Software" 18
    "1.4 Extending Lisp" 19
    "1.5 Why Lisp (or When)" 21
"Functions" 22
    "2.1 Functions as Data" 22
    "2.2 Defining Functions" 23
    "2.3 Functional Arguments" 26
    "2.4 Functions as Properties" 28
    "2.5 Scope" 29
    "2.6 Closures" 30
    "2.7 Local Functions" 34
    "2.8 Tail-Recursion" 35
    "2.9 Compilation" 37
    "2.10 Functions from Lists" 40
[--snip--]

You could save the output to a file called toc

$ pdftocgen onlisp.pdf < recipe.toml > toc

and import it to the PDF file using pdftocio:

$ pdftocio -o output.pdf onlisp.pdf < toc

Please read the homepage for the details on how to use this toolset. I hope you find it useful.

| improve this answer | |
0

The full Adobe Acrobat Pro ver.8 is available as a free legal download from http://www.techspot.com/downloads/4683-adobe-acrobat-8-free.html for both Mac and Windows. Sure, it's not the latest version, but free is good, and it works just fine for adding or editing a table of contents.

| improve this answer | |
  • That does not look legal - I would suspect it of having viruses and trojans. Where on Adobe's site can you get it? or at least an Adobe document saying it is legal – mmmmmm Aug 25 '16 at 18:16
  • Now, at least, it's only free for 7 days. – Diagon Aug 3 '19 at 13:20
0

Here is my repository that I plan to automate the procedure. https://github.com/aminya/tocPDF

For now, it is the manual procedure (which is also inspired by other people answers).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.