diff --git a/examples/links.js b/examples/links.js index d5aeec78b..706004d1f 100644 --- a/examples/links.js +++ b/examples/links.js @@ -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', diff --git a/src/printer.js b/src/printer.js index c108459c8..1b22c8ace 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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; @@ -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) {