delete_bookmarks
Delete bookmarks
Usage
pdftl
<input>delete_bookmarks[<page_spec>...][recursive][no_dest]output<file>[<option>...]
Details
Delete bookmarks (outline entries) from a PDF.
Without a page spec, all bookmarks are removed. With one or more page specs, only bookmarks whose destination falls within the matched pages are targeted for deletion.
Multiple page specs are treated as a union — a bookmark is matched if its
destination page falls within any of the given specs. Page specs use the
standard pdftl syntax; see pdftl help pages for details.
Flags (recursive, no_dest) apply to the entire operation, not per page spec.
Deletion model
Bookmarks are matched by destination page. A bookmark is “matched” if the page it points to falls within the union of all given page specs.
Two modes control how matched bookmarks with unmatched descendants are handled:
safe (default) A matched bookmark is only deleted if all of its descendants are also matched (and will therefore also be deleted). If a matched bookmark has any unmatched descendant anywhere in its subtree, it is skipped and a warning is emitted. The tree structure of surviving bookmarks is always preserved exactly — no promotion occurs.
recursive A matched bookmark and its entire subtree are deleted, regardless of whether any descendants are matched. Use with care.
The algorithm processes the tree bottom-up (post-order), so children are
evaluated before their parents. This means a matched parent whose children
are all independently matched will be cleanly deleted in safe mode, even
without specifying recursive.
Destination-less bookmarks
Some bookmarks have no page destination — they are purely structural, grouping children without linking to any page. By default these are treated as unmatched: they survive, and they block deletion of matched ancestors in safe mode.
no_dest
Treat destination-less bookmarks as matched. They no longer block ancestor
deletion in safe mode, and are themselves deleted if all their descendants are
also matched (or they have no surviving children after deletion).
With recursive, no_dest is redundant — descendants are swept up regardless.
Worked examples
Given the outline tree (page numbers shown, nested lists are children):
[1, [2, 3], 4, [5, [6]]]
delete_bookmarks 2
=> [1, [3], 4, [5, [6]]]
bookmark 2 has no unmatched children, deleted cleanly.
delete_bookmarks 1
=> [1, [2, 3], 4, [5, [6]]] (unchanged)
safe: bookmark 1 skipped+warned because child 3 is unmatched.
delete_bookmarks 1-3
=> [4, [5, [6]]]
safe: 2 deleted first (no unmatched children); 3 deleted (no
children); 1 now has no unmatched descendants, deleted too.
delete_bookmarks 1 recursive
=> [4, [5, [6]]]
bookmark 1 and entire subtree [2, 3] deleted.
delete_bookmarks 5
=> [1, [2, 3], 4, [5, [6]]] (unchanged)
safe: bookmark 5 skipped+warned because child 6 is unmatched.
delete_bookmarks 5-6
=> [1, [2, 3], 4]
safe: 6 deleted first; 5 now has no unmatched descendants, deleted.
delete_bookmarks 1-3 5-6
=> [4]
multiple page specs, union of pages 1,2,3,5,6 matched.
Clearing all bookmarks
To remove the entire outline, omit the page spec:
pdftl in.pdf delete_bookmarks output out.pdf
Examples
Delete all bookmarks
pdftl in.pdf delete_bookmarks output out.pdf
Delete bookmarks pointing to pages 1 through 5 (safe mode)
pdftl in.pdf delete_bookmarks 1-5 output out.pdf
Delete bookmarks pointing to pages 1-5 or odd pages 7-20
pdftl in.pdf delete_bookmarks 1-5 7-20odd output out.pdf
Delete bookmarks pointing to page 3 and all their descendants
pdftl in.pdf delete_bookmarks 3 recursive output out.pdf
Delete bookmarks pointing to pages 1-5, treating destination-less bookmarks as matched
pdftl in.pdf delete_bookmarks 1-5 no_dest output out.pdf
Delete bookmarks pointing to odd pages, including all descendants
pdftl in.pdf delete_bookmarks odd recursive output out.pdf
Tags: in_place, bookmarks, outlines, delete
Source: pdftl.operations.delete_bookmarks
Read online: https://pdftl.readthedocs.io/en/latest/operations/delete_bookmarks.html
Type: Operation