How to create hyperlink in PDF using jsPDF js library?

JavaScript:

    function demoJsPdf() {
        var doc = new jsPDF("landscape", "mm", "a4");

        doc.setFontSize(22);
        doc.text(20, 20, 'This is a exmaple of jsPDF');

        doc.setFontSize(16);
        doc.text(20, 30, 'This example is created by dsharma4u29.');
        doc.fromHTML('<a href="javascript:window.print()">Print</a>', 20, 60, {'width': 10, 'elementHandlers': specialElementHandlers});

        var iframe = document.getElementById('output');
        iframe.style.width = '100%';
        iframe.style.height = '400px';
        iframe.src = doc.output('datauristring');
    }

    var specialElementHandlers = function() {
        return;
    }

HTML:

    <html>
    <body>

    <div>
        <a href="javascript:demoJsPdf()" class="button">Run Code 2</a>
    <iframe id="output"></iframe>
    </div>

    </body>
    </html>

Now the text "Run Code 2" should appear as a hyperlink, but it just displays as plain text, not a hyperlink. How can I achieve this as a hyper link in a PDF?

+4
source share
2 answers

In the current version, all links are automatically if you have the entire URL written out

Example: doc.text(20, 30, 'http://www.google.com');

Will automatically contact Google.

, - , - URL- . , , , URL-, .

+3

jsPDF .link() .textWithLink(), 2014 . , , .

html2pdf, HTML PDF <a>.

+2
source

All Articles