Removing outlines from PDFs using JavaScript

To remove an outline by title in an existing document.

JavaScript (v6.0+)

1<html>
2 <script src="../lib/core/CoreControls.js"></script>
3 <script src="../lib/core/pdf/PDFNet.js"></script>
4 <script>
5 (async function() {
6 CoreControls.setWorkerPath('../lib/core');
7 const doc = await PDFNet.PDFDoc.createFromURL(filename);
8
9 // how to find and delete a outline by title text.
10 const firstOutline = await doc.getFirstBookmark();
11 const foo = await firstOutline.find('foo');
12 if (await foo.isValid()) {
13 foo.delete();
14 }
15 })()
16 </script>
17</html>

Read, add, edit PDF outlines Full code sample which illustrates how to read and edit existing outline items and create new bookmarks using the high-level API

About removing an outline

The PDF Bookmarks class also allows you to quickly find Outlines based on the title text. For example, the above code snippet looks for a Outline called foo and then removes it from the outline tree.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales