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
Syncfusion<sup>®</sup> PDF provides support to insert, remove and modify the bookmarks in the PDF Document.
10
+
Syncfusion<sup>®</sup> PDF provides support to insert, remove, and modify the bookmarks in the PDF Document.
11
11
12
-
## Adding Bookmarks in a PDF
12
+
## Adding bookmarks to a PDF
13
13
14
14
This example demonstrates how to add bookmarks to a PDF document using the `PdfBookmark` class. Bookmarks provide an easy way to navigate through different sections of a PDF file.
15
15
16
16
{% tabs %}
17
-
{% highlight javascript tabtitle="TypeScript" %}
18
-
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
17
+
{% highlight typescript tabtitle="TypeScript" %}
18
+
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfBookmark, PdfDestination} from '@syncfusion/ej2-pdf';
19
19
20
20
// Create a new PDF document
21
21
let document: PdfDocument = new PdfDocument();
22
-
// Add page
22
+
// Add a page
23
23
let page: PdfPage = document.addPage();
24
24
// Get the bookmarks
25
25
let bookmarks: PdfBookmarkBase = document.bookmarks;
26
-
// Add a new outline to the PDF document
27
-
let bookmark: PdfBookmark = bookmarks.add('Introduction');
28
-
// Sets destination to the bookmark
29
-
bookmark.destination = new PdfDestination(page, { x: 100, y: 200 });
26
+
// Add a new bookmark to the PDF document
27
+
let bookmark: PdfBookmark = bookmarks.add('Introduction', 0, {
namedDestination: new ej.pdf.PdfNamedDestination('First', new ej.pdf.PdfDestination(page, { x: 0, y: 10 }, {zoom: 1 })),
50
+
color: { r: 0, g: 0, b: 255 },
51
+
textStyle: ej.pdf.PdfTextStyle.bold});
47
52
// Save the document
48
-
document.save('Output.pdf');
53
+
document.save('output.pdf');
49
54
// Close the document
50
55
document.destroy();
51
56
52
57
{% endhighlight %}
53
58
{% endtabs %}
54
59
55
-
## Adding Bookmarks in an existing PDF document
60
+
## Inserting bookmarks into an existing PDF
56
61
57
-
This example demonstrates how to add bookmarks to an existing PDF document using the `PdfBookmark` class. This allows you to enhance navigation in already created PDF document.
62
+
This example demonstrates how to insert bookmarks at a specific position in an existing PDF document using the `PdfBookmark` class. This feature allows precise control over bookmark order.
58
63
59
64
{% tabs %}
60
-
{% highlight javascript tabtitle="TypeScript" %}
61
-
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
65
+
{% highlight typescript tabtitle="TypeScript" %}
66
+
import {PdfDocument, PdfPage, PdfBookmark, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
62
67
63
68
// Load an existing PDF document
64
69
let document: PdfDocument = new PdfDocument(data);
65
-
// Get page
66
-
let page: PdfPage = document.getPage(0);
70
+
// Get the first page
71
+
let page: PdfPage = document.getPage(0) as PdfPage;
67
72
// Get the bookmarks
68
73
let bookmarks: PdfBookmarkBase = document.bookmarks;
69
-
// Gets the bookmark at the specified index
70
-
let bookmark: PdfBookmark = bookmarks.at(0) as PdfBookmark;
71
-
// Set the destination
74
+
// Add a new bookmark at the specified bookmark index
75
+
let bookmark: PdfBookmark = bookmarks.add('Introduction', 1);
76
+
// Sets destination to the bookmark
72
77
bookmark.destination = new PdfDestination(page, { x: 100, y: 200 });
73
78
// Save the document
74
-
document.save('Output.pdf');
79
+
document.save('output.pdf');
75
80
// Close the document
76
81
document.destroy();
77
-
82
+
78
83
{% endhighlight %}
79
84
{% highlight javascript tabtitle="JavaScript" %}
85
+
80
86
// Load an existing PDF document
81
87
var document = new ej.pdf.PdfDocument(data);
82
-
// Get page
88
+
// Get the first page
83
89
var page = document.getPage(0);
84
90
// Get the bookmarks
85
91
var bookmarks = document.bookmarks;
86
-
// Get the bookmark at the specified index
87
-
var bookmark = bookmarks.at(0);
88
-
// Set the destination
92
+
// Add a new bookmark at the specified bookmark index
93
+
var bookmark = bookmarks.add('Introduction', 1);
94
+
// Set destination to the bookmark
89
95
bookmark.destination = new ej.pdf.PdfDestination(page, { x: 100, y: 200 });
90
96
// Save the document
91
-
document.save('Output.pdf');
97
+
document.save('output.pdf');
92
98
// Close the document
93
99
document.destroy();
94
100
95
101
{% endhighlight %}
96
102
{% endtabs %}
97
103
98
-
## Inserting Bookmarks in an existing PDF
104
+
## Nested Bookmark
99
105
100
-
This example demonstrates how to insert bookmarks at a specific position in an existing PDF document using the `PdfBookmark` class. This feature allows precise control over bookmark order.
106
+
This example demonstrates how to create hierarchical (parent-child) bookmarks in a PDF using the PdfBookmark class. This feature allows organizing content with nested bookmark structures for easier navigation.
101
107
102
108
{% tabs %}
103
-
{% highlight javascript tabtitle="TypeScript" %}
104
-
import {PdfDocument, PdfPage, PdfBookmarkBase, PdfDestination} from '@syncfusion/ej2-pdf';
109
+
{% highlight typescript tabtitle="TypeScript" %}
110
+
import {PdfDocument, PdfPage, PdfBookmark, PdfBookmarkBase, PdfTextStyle, PdfNamedDestination, PdfDestination} from '@syncfusion/ej2-pdf';
105
111
106
-
// Load an existing PDF document
107
-
let document: PdfDocument = new PdfDocument(data);
108
-
// Get the first page
109
-
let page: PdfPage = document.getPage(0) as PdfPage;
112
+
// Create a new PDF document
113
+
let document: PdfDocument = new PdfDocument();
114
+
// Add a page
115
+
let page: PdfPage = document.addPage();
110
116
// Get the bookmarks
111
117
let bookmarks: PdfBookmarkBase = document.bookmarks;
112
-
// Add a new outline to the PDF document
113
-
let bookmark: PdfBookmark = bookmarks.add('Introduction', 1);
114
-
// Sets destination to the bookmark
115
-
bookmark.destination = new PdfDestination(page, { x: 100, y: 200 });
118
+
// Add a new bookmark to the PDF document
119
+
let bookmark: PdfBookmark = bookmarks.add('Introduction', 0, {
namedDestination: new ej.pdf.PdfNamedDestination('Second', new ej.pdf.PdfDestination(page, { x: 0, y: 10 }, {zoom: 1 })),
154
+
color: { r: 0, g: 0, b: 255 },
155
+
textStyle: ej.pdf.PdfTextStyle.bold});
133
156
// Save the document
134
-
document.save('Output.pdf');
157
+
document.save('output.pdf');
135
158
// Close the document
136
159
document.destroy();
137
160
138
161
{% endhighlight %}
139
162
{% endtabs %}
140
163
141
-
## Removing Bookmarks from an existing PDF
164
+
## Removing bookmarks from an existing PDF
142
165
143
166
This example demonstrates how to remove bookmarks from an existing PDF document using the `PdfBookmark` class.
167
+
144
168
{% tabs %}
145
-
{% highlight javascript tabtitle="TypeScript" %}
169
+
{% highlight typescript tabtitle="TypeScript" %}
146
170
import {PdfDocument, PdfPage, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
147
171
148
172
// Load an existing PDF document
@@ -154,12 +178,13 @@ let bookmarks: PdfBookmarkBase = document.bookmarks;
154
178
// Remove specified bookmark from the document.
155
179
bookmarks.remove('Introduction');
156
180
// Save the document
157
-
document.save('Output.pdf');
181
+
document.save('output.pdf');
158
182
// Close the document
159
183
document.destroy();
160
184
161
185
{% endhighlight %}
162
186
{% highlight javascript tabtitle="JavaScript" %}
187
+
163
188
// Load an existing PDF document
164
189
var document = new ej.pdf.PdfDocument(data);
165
190
// Get the first page
@@ -169,58 +194,55 @@ var bookmarks = document.bookmarks;
169
194
// Remove specified bookmark from the document
170
195
bookmarks.remove('Introduction');
171
196
// Save the document
172
-
document.save('Output.pdf');
197
+
document.save('output.pdf');
173
198
// Close the document
174
199
document.destroy();
175
200
176
201
{% endhighlight %}
177
202
{% endtabs %}
178
203
179
-
## Removing Bookmark from the document at the specified index
204
+
## Removing a bookmark from the document at a specified index
180
205
181
206
This example demonstrates how to remove bookmarks from the document at the specific index using the `PdfBookmark` class.
182
207
183
208
{% tabs %}
184
-
{% highlight javascript tabtitle="TypeScript" %}
185
-
import {PdfDocument, PdfPage, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
209
+
{% highlight typescript tabtitle="TypeScript" %}
210
+
import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
186
211
187
212
// Load an existing PDF document
188
213
let document: PdfDocument = new PdfDocument(data);
189
-
// Get the first page
190
-
let page: PdfPage = document.getPage(0) as PdfPage;
191
214
// Get the bookmarks
192
215
let bookmarks: PdfBookmarkBase = document.bookmarks;
193
216
// Remove the bookmark from the document at the index 1.
194
217
bookmarks.remove(1);
195
218
// Save the document
196
-
document.save('Output.pdf');
219
+
document.save('output.pdf');
197
220
// Close the document
198
221
document.destroy();
199
222
200
223
{% endhighlight %}
201
224
{% highlight javascript tabtitle="JavaScript" %}
225
+
202
226
// Load an existing PDF document
203
227
var document = new ej.pdf.PdfDocument(data);
204
-
// Get the first page
205
-
var page = document.getPage(0);
206
228
// Get the bookmarks
207
229
var bookmarks = document.bookmarks;
208
230
// Remove the bookmark from the document at index 1
209
231
bookmarks.remove(1);
210
232
// Save the document
211
-
document.save('Output.pdf');
233
+
document.save('output.pdf');
212
234
// Close the document
213
235
document.destroy();
214
236
215
237
{% endhighlight %}
216
238
{% endtabs %}
217
239
218
-
## Removing all the Bookmark from the collection
240
+
## Removing all bookmarks from the collection
219
241
220
-
This example demonstrates how to removes all the bookmarks from the collection using the `PdfBookmark` class.
242
+
This example demonstrates how to removes all bookmarks from the collection using the `PdfBookmark` class.
221
243
222
244
{% tabs %}
223
-
{% highlight javascript tabtitle="TypeScript" %}
245
+
{% highlight typescript tabtitle="TypeScript" %}
224
246
import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
225
247
226
248
// Load an existing PDF document
@@ -229,52 +251,56 @@ let document: PdfDocument = new PdfDocument(data);
229
251
let bookmarks: PdfBookmarkBase = document.bookmarks;
230
252
// Remove all the bookmark from the collection.
231
253
bookmarks.clear();
232
-
// Get count after removal of all outlines.
254
+
// Get the count after removal of all bookmarks
233
255
let count: number = bookmarks.count;
234
256
// Save the document
235
-
document.save('Output.pdf');
257
+
document.save('output.pdf');
236
258
// Destroy the document
237
259
document.destroy();
238
260
239
261
{% endhighlight %}
240
262
{% highlight javascript tabtitle="JavaScript" %}
263
+
241
264
// Load an existing PDF document
242
265
var document = new ej.pdf.PdfDocument(data);
243
266
// Get the bookmarks
244
267
var bookmarks = document.bookmarks;
245
268
// Remove all the bookmarks from the collection
246
269
bookmarks.clear();
247
-
// Get count after removal of all outlines
270
+
// Get the count after removal of all bookmarks
248
271
var count = bookmarks.count;
249
272
// Save the document
250
-
document.save('Output.pdf');
273
+
document.save('output.pdf');
251
274
// Destroy the document
252
275
document.destroy();
253
276
254
277
{% endhighlight %}
255
278
{% endtabs %}
256
279
257
-
## Bookmark page index in an existing PDF document
280
+
## Getting a bookmark's page index in an existing PDF document
258
281
259
282
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.
260
283
261
284
{% tabs %}
262
-
{% highlight javascript tabtitle="TypeScript" %}
285
+
{% highlight typescript tabtitle="TypeScript" %}
263
286
import {PdfDocument, PdfBookmarkBase} from '@syncfusion/ej2-pdf';
264
287
265
288
// Load an existing PDF document
266
289
let document: PdfDocument = new PdfDocument(data);
267
290
// Get bookmarks
268
-
let bookmarks: PdfBookmarkBase = document.bookmarks;
269
-
// Get bookmark at the specified index
270
-
let pageIndex: number = bookmarks.destination.pageIndex;
291
+
let bookmarks: PdfBookmarkBase = document.bookmarks;
292
+
// Get the first bookmark (or any specific one)
293
+
let bookmark = bookmarks.at(0);
294
+
// Get the page index of the bookmark's destination
295
+
let pageIndex: number = bookmark.destination.pageIndex;
271
296
// Save the document
272
-
document.save('Output.pdf');
297
+
document.save('output.pdf');
273
298
// Close the document
274
299
document.destroy();
275
300
276
301
{% endhighlight %}
277
302
{% highlight javascript tabtitle="JavaScript" %}
303
+
278
304
// Load an existing PDF document
279
305
var document = new ej.pdf.PdfDocument(data);
280
306
// Get bookmarks
@@ -284,7 +310,7 @@ var bookmark = bookmarks.at(0);
284
310
// Get the page index of the bookmark's destination
0 commit comments