mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Add support for link to another page (#701)
* Link to a page * Text link can go to page 0 * Update annotations.coffee
This commit is contained in:
parent
b9fc5b04a8
commit
a531f433c1
@ -27,13 +27,27 @@ module.exports =
|
||||
|
||||
link: (x, y, w, h, url, options = {}) ->
|
||||
options.Subtype = 'Link'
|
||||
options.A = @ref
|
||||
S: 'URI'
|
||||
URI: new String url
|
||||
|
||||
options.A.end()
|
||||
|
||||
if typeof url is 'number'
|
||||
# Link to a page in the document (the page must already exist)
|
||||
pages = @_root.data.Pages.data
|
||||
if url >= 0 and url < pages.Kids.length
|
||||
options.A = @ref
|
||||
S: 'GoTo'
|
||||
D: [pages.Kids[url], 'XYZ', null, null, null]
|
||||
options.A.end()
|
||||
else
|
||||
throw new Error "The document has no page #{url}"
|
||||
|
||||
else
|
||||
# Link to an external url
|
||||
options.A = @ref
|
||||
S: 'URI'
|
||||
URI: new String url
|
||||
options.A.end()
|
||||
|
||||
@annotate x, y, w, h, options
|
||||
|
||||
|
||||
_markup: (x, y, w, h, options = {}) ->
|
||||
[x1, y1, x2, y2] = @_convertRect x, y, w, h
|
||||
options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1]
|
||||
@ -90,4 +104,4 @@ module.exports =
|
||||
x2 = m0 * x2 + m2 * y2 + m4
|
||||
y2 = m1 * x2 + m3 * y2 + m5
|
||||
|
||||
return [x1, y1, x2, y2]
|
||||
return [x1, y1, x2, y2]
|
||||
|
||||
@ -191,7 +191,7 @@ module.exports =
|
||||
renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1))
|
||||
|
||||
# create link annotations if the link option is given
|
||||
if options.link
|
||||
if options.link?
|
||||
@link x, y, renderedWidth, @currentLineHeight(), options.link
|
||||
|
||||
# create underline or strikethrough line
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user