You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Document-Processing/PDF/PDF-Library/javascript/Bookmarks.md
+61-6Lines changed: 61 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,10 +16,12 @@ This example demonstrates how to add bookmarks to a PDF document using the `PdfB
16
16
{% tabs %}
17
17
{% highlight c# tabtitle="TypeScript" %}
18
18
19
-
import {PdfDocument, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
19
+
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
20
20
21
21
// Create a new PDF document
22
22
let document: PdfDocument = new PdfDocument();
23
+
// Add page
24
+
let page: PdfPage = document.addPage();
23
25
// Get the bookmarks
24
26
let bookmarks: PdfBookmarkBase = document.bookmarks;
25
27
// Add a new outline to the PDF document
@@ -41,10 +43,12 @@ This example demonstrates how to add bookmarks to an existing PDF document using
41
43
{% tabs %}
42
44
{% highlight c# tabtitle="TypeScript" %}
43
45
44
-
import {PdfDocument, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
46
+
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
45
47
46
48
// Load an existing PDF document
47
49
let document: PdfDocument = new PdfDocument(data, password);
50
+
// Get page
51
+
let page: PdfPage = document.getPage(0);
48
52
// Get the bookmarks
49
53
let bookmarks: PdfBookmarkBase = document.bookmarks;
50
54
// Gets the bookmark at the specified index
@@ -75,7 +79,7 @@ This example demonstrates how to insert bookmarks at a specific position in an e
75
79
// Get the bookmarks
76
80
let bookmarks: PdfBookmarkBase = document.bookmarks;
77
81
// Add a new outline to the PDF document
78
-
let bookmark: PdfBookmark = bookmarks.add('Introduction');
82
+
let bookmark: PdfBookmark = bookmarks.add('Introduction', 1);
79
83
// Sets destination to the bookmark
80
84
bookmark.destination = new PdfDestination(page, {x: 100, y: 200});
81
85
// Save the document
@@ -88,8 +92,7 @@ This example demonstrates how to insert bookmarks at a specific position in an e
88
92
89
93
## Removing Bookmarks from an existing PDF
90
94
91
-
This example demonstrates how to remove bookmarks from an existing PDF document using the `PdfBookmark` class. Removing bookmarks helps clean up unnecessary navigation links.
92
-
95
+
This example demonstrates how to remove bookmarks from an existing PDF document using the `PdfBookmark` class.
93
96
{% tabs %}
94
97
{% highlight c# tabtitle="TypeScript" %}
95
98
@@ -111,6 +114,58 @@ This example demonstrates how to remove bookmarks from an existing PDF document
111
114
{% endhighlight %}
112
115
{% endtabs %}
113
116
117
+
## Removing Bookmark from the document at the specified index
118
+
119
+
This example demonstrates how to remove bookmarks from the document at the specific index using the `PdfBookmark` class.
120
+
121
+
{% tabs %}
122
+
{% highlight c# tabtitle="TypeScript" %}
123
+
124
+
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
125
+
126
+
// Load an existing PDF document
127
+
let document: PdfDocument = new PdfDocument(data, password);
128
+
// Get the first page
129
+
let page: PdfPage = document.getPage(0) as PdfPage;
130
+
// Get the bookmarks
131
+
let bookmarks: PdfBookmarkBase = document.bookmarks;
132
+
// Remove the bookmark from the document at the index 1.
133
+
bookmarks.remove(1);
134
+
// Sets destination to the bookmark
135
+
bookmark.destination = new PdfDestination(page, {x: 10, 10});
136
+
// Save the document
137
+
document.save('Output.pdf');
138
+
// Close the document
139
+
document.destroy();
140
+
141
+
{% endhighlight %}
142
+
{% endtabs %}
143
+
144
+
## Removing all the Bookmark from the collection
145
+
146
+
This example demonstrates how to removes all the bookmarks from the collection using the `PdfBookmark` class.
147
+
148
+
{% tabs %}
149
+
{% highlight c# tabtitle="TypeScript" %}
150
+
151
+
import {PdfDocument, PdfPage, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
152
+
153
+
// Load an existing PDF document
154
+
let document: PdfDocument = new PdfDocument(data, password);
155
+
// Get the bookmarks
156
+
let bookmarks: PdfBookmarkBase = document.bookmarks;
157
+
// Remove all the bookmark from the collection.
158
+
bookmarks.clear();
159
+
// Get count after removal of all outlines.
160
+
let count: number = bookmarks.count;
161
+
// Save the document
162
+
document.save('Output.pdf');
163
+
// Destroy the document
164
+
document.destroy();
165
+
166
+
{% endhighlight %}
167
+
{% endtabs %}
168
+
114
169
## Bookmark page index in an existing PDF document
115
170
116
171
This example demonstrates how to retrieve the page index associated with a bookmark in an existing PDF document using the `PdfBookmark` class. This helps identify the exact location of the bookmark.
@@ -125,7 +180,7 @@ This example demonstrates how to retrieve the page index associated with a bookm
125
180
// Get bookmarks
126
181
let bookmarks: PdfBookmarkBase = document.bookmarks;
127
182
// Get bookmark at the specified index
128
-
let bookmark: PdfBookmark = bookmarks.at(0) as PdfBookmark;
183
+
let pageIndex: number = bookmarks.destination.pageIndex;
0 commit comments