Skip to content

Commit

Permalink
added feature linkToPage and linkToDestination for image #1934
Browse files Browse the repository at this point in the history
master commit: b914c7e
  • Loading branch information
liborm85 committed Feb 26, 2020
1 parent 38f92c2 commit 4890771
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var docDefinition = {
{ text: 'Link to header 2', linkToDestination: 'header2', decoration: 'underline' },
'Links are also supported with images:',
{ image: 'fonts/sampleImage.jpg', width: 150, link: 'http://pdfmake.org' },
'With link to page',
{ image: 'fonts/sampleImage.jpg', width: 150, linkToPage: 2 },
'And link to header 2',
{ image: 'fonts/sampleImage.jpg', width: 150, linkToDestination: 'header2' },
{ text: 'Header on page 2', fontSize: 18, bold: true, pageBreak: 'before' },
{ text: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sollicitudin. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Suspendisse nisl. Mauris elementum mauris vitae tortor. Phasellus et lorem id felis nonummy placerat. Aliquam erat volutpat. In laoreet, magna id viverra tincidunt, sem odio bibendum justo, vel imperdiet sapien wisi sed libero. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Donec ipsum massa, ullamcorper in, auctor et, scelerisque sed, est. Etiam bibendum elit eget erat. Nullam rhoncus aliquam metus. Proin mattis lacinia justo. Nullam sit amet magna in magna gravida vehicula. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Integer lacinia. Duis sapien nunc, commodo et, interdum suscipit, sollicitudin et, dolor.' },
'\n\n',
Expand Down
9 changes: 8 additions & 1 deletion src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ function renderVector(vector, pdfKitDoc) {

vector.color = gradient;
}

var fillOpacity = isNumber(vector.fillOpacity) ? vector.fillOpacity : 1;
var strokeOpacity = isNumber(vector.strokeOpacity) ? vector.strokeOpacity : 1;

Expand All @@ -611,6 +611,13 @@ function renderImage(image, x, y, pdfKitDoc) {
if (image.link) {
pdfKitDoc.link(image.x, image.y, image._width, image._height, image.link);
}
if (image.linkToPage) {
pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [image.linkToPage, 0, 0] }).end();
pdfKitDoc.annotate(image.x, image.y, image._width, image._height, { Subtype: 'Link', Dest: [image.linkToPage - 1, 'XYZ', null, null, null] });
}
if (image.linkToDestination) {
pdfKitDoc.goTo(image.x, image.y, image._width, image._height, image.linkToDestination);
}
}

function renderSVG(svg, x, y, pdfKitDoc, fontProvider) {
Expand Down

0 comments on commit 4890771

Please sign in to comment.