How can I edit the Table of Contents of a PDF file on Linux? I tried pdfedit but I can't find where the content table list is stored.
- 3,841
- 993
9 Answers
A very nice alternative is to use HandyOutliner, which works for PDF and DJVU. It also provides very good functionality for editing the table of contents. It works on GNU/linux with mono.
Additionally, there is the very handy python script called document-contents-extractor to extract contents from PDF's or DJVU's. It can be installed with pip (for me on Fedora pip3 install --user document-contents-extractor). It requires some additional dependencies to be installed as found in the instructions here.
EDIT
Actually, the best tool for adding a TOC to a PDF is Emacs using the doc-toc package. Using it requires only minimal knowledge of Emacs (if you know Vim keybindings already, then use Spacemacs, with the toc layer). 1
As mentioned by Sam Liao, the best way to add TOC to digitally produced (i.e. 'non-scanned') documents is pdf-tocgen. It is a very powerful tool. The Emacs doc-toc package, makes it even easier to use.
1 On Windows, you'd probably prefer using Emacs via WSL, as otherwise it is not easy to setup doc-toc (for GNU/linux or OSX its easy)
END EDIT
- 203
You can use pdf.togen to edit the toc.
- use
pdftocioto get thetocof the pdf - edit the
toc - write back to the pdf with
pdftociocommand.
Further more, if the pdf has no toc, you can also use pdf.tocgen construct the toc with multiple ways:
- Manually edit a
tocfile and write to the pdf (this is useful when there is no way automatically detect the toc, for example: a pdf file each page is scanned image). - Use tools in
pdf.tocgento construct the toc automatically based on the different styles each level oftocuses. A small script can be used to automate this process once you understand howpdf.tocgenworks.
- 476
I have answered it in another stackexchange thread but for completeness' sake there is also Pdf4Qt (Pdf4QtEditor) can also do this while you are viewing the PDF.
You can use the editor variant of the tool (it also comes with a diff tool and a pdf viewer) and then manually add the entries in the outline/bookmarks sidebar and set the targets. You can also rename them and delete from the Outlines pane.
Moreover, it also includes handy editor features severely lacking in evince/zathura/okular.
(I have no affiliation with the tool, simply found it useful hence replying here to let others know.).
You can see on this picture on how the toolbar looks and how to edit in bookmarks. From https://github.com/JakubMelka/PDF4QT/issues/76
I use two programs, PdfMod and JPdfBookmarks (see also this SourceForge page and the manual).
I found JPdfBookmarks to be superiour: for example, one can easily change the level of a nested bookmark, or exchange two bookmarks, which I was not able to do with the PdfMod.
- 1,704
- 13
- 13
What has not been clearly mentioned that PDFedit had no inbuilt means to edit the Outline "Bookmarks" so take this example it was unable to work with UTF entries.

With most Bookmarks editors, either you easily edit in place with a GUI, here moving Page3 up to between 2 and 4.

Or export edit as text and reimport.
Most modern cross platform export & import method is coherent cpdf -list-bookmarks -utf8 source.pdf bookmarks.txt edit and re-import with the corrections.

That can be easily shell scripted for in-situ edits and thus could have been similarly done from PDFedit
The question is about Linux but the logical steps are the same which ever OS
Pseudo code
"%cpdf%" -list-bookmarks -utf8 "%~dpn1.pdf" 2>nul 1>"%temp%\bookmarks-out.txt"
for example to add an entry use
echo %BkLvl% "%BkTxt%" %2 "[%2 /%BkAct%]">>"%temp%\bookmarks-out.txt"
finally add back the edits from the backup.pdf to source.pdf
"%cpdf%" -add-bookmarks "%temp%\bookmarks-out.txt" "%~dpn1-bak.pdf" -o "%~dpn1.pdf"
- 1,248
I use Jpdf Tweak. The outline can be edited in the program or imported from csv using this format:
<Depth>;;<Title>;<Page>
- 250
HandyOutliner a great tool. I used it on Windows 11. Just remember to press "write outline" to save the work. The save function seems to be broken. But the "write outline" would work everytime. Your file should not be open in another program. To work on it at same time, make a copy of file and than open the copy, and write to original file.
- 1
SIMPLE to edit.
To edit the page number if the table of contents is leading to the wrong page: Open the edit tool in the pdf. Right click on the line you wish to edit. A menu will open ... if you have a link there, it will give you an edit link option ... click on it and the link properties opens. Select the actions tab where you can edit the page number. Keep in mind the labels on the pages may not be the same number if you started page 1 on other than the cover page.
If you only have text and no page link: Open the edit tool in the pdf. Select "Link" > "Add/Edit Web or Document Link" in the menu. Use the crosshair to select the area of text where you want to put the link... a "Create Link" should show once you have drawn the box area. Choose the Link Action "Go to a page view and hit "Next". A box "Create Go to View" should pop up. Scroll to the page you wish the link to go tov and draw a box around the area (full page or section). Choose button to "Set Link". Close the edit tool and try the link.
I find if I set the bookmarks up myself using the formula with switches in Word rather than trusting the automatic bookmarking, I have better control of the results in the conversion. I also make sure I export the Word using the Export>Create PDF/XPS document to better replicate Word with less conversion issues.
PDF is an image format. There is no storage of the contents of the table, only a "picture" of it. It can only be edited if the PDF's OCR can read the table as text, which is unlikely. You will need to use another application to create the table and then convert it to PDF.
- 1,265
