-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34cf8d5
commit f91bdd6
Showing
7 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Outlines in PDFKit | ||
|
||
Outlines are the heirachical bookmarks that display in some PDF readers. Currently only page bookmarks are supported, but more may be added in the future. They are simple to add and only require a single method: | ||
|
||
* `addItem(title, options)` | ||
Here is an example of adding a bookmark with a single child bookmark. | ||
|
||
# Get a reference to the Outline root | ||
outline = doc.outline | ||
# Add a top-level bookmark | ||
top = outline.addItem('Top Level') | ||
# Add a sub-section | ||
top.addItem('Sub-section') | ||
## Options | ||
|
||
The `options` parameter currently only has one property: `expanded`. If this value is set to `true` then all of that section's children will be visible by default. This value defaults to `false`. | ||
|
||
In this example the 'Top Level' section will be expanded to show 'Sub-section'. | ||
|
||
# Add a top-level bookmark | ||
top = outline.addItem('Top Level', { expanded: true }) | ||
# Add a sub-section | ||
top.addItem('Sub-section') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
PDFOutline = require '../outline' | ||
|
||
module.exports = | ||
initOutline: () -> | ||
@outline = new PDFOutline(this, null, null, null) | ||
|
||
endOutline: () -> | ||
@outline.endOutline() | ||
if @outline.children.length > 0 | ||
@_root.data.Outlines = @outline.dictionary | ||
@_root.data.PageMode = 'UseOutlines' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
PDFObject = require './object' | ||
PDFPage = require './page' | ||
|
||
class PDFOutline | ||
constructor: (@document, parent, title, dest, @options = { expanded: false }) -> | ||
|
||
@outlineData = {} | ||
|
||
if dest != null | ||
@outlineData['Dest'] = [dest.dictionary, 'Fit'] | ||
|
||
if parent != null | ||
@outlineData['Parent'] = parent | ||
|
||
if title != null | ||
@outlineData['Title'] = new String(title) | ||
|
||
@dictionary = @document.ref @outlineData | ||
@children = [] | ||
|
||
addItem: (title, options = { expanded: false }) -> | ||
result = new PDFOutline(@document, @dictionary, title, @document.page, options) | ||
@children.push(result) | ||
|
||
return result | ||
|
||
endOutline: () -> | ||
if @children.length > 0 | ||
if @options.expanded | ||
@outlineData.Count = @children.length | ||
|
||
[first, ..., last] = @children | ||
@outlineData.First = first.dictionary | ||
@outlineData.Last = last.dictionary | ||
|
||
for i in [0...@children.length] | ||
child = @children[i] | ||
if i > 0 | ||
child.outlineData.Prev = @children[i-1].dictionary | ||
if i < @children.length - 1 | ||
child.outlineData.Next = @children[i+1].dictionary | ||
child.endOutline() | ||
|
||
@dictionary.end() | ||
|
||
|
||
module.exports = PDFOutline |