user1018146
user1018146

Reputation:

Create link in pdf with tcpdf

How can I create a link with TCPDF?

When using the writeHTML() function and passing my whole html content, TCPDF doesn't make my links clickable. They are blue and underlined but I cannot click them.

Here is what I did.

$html = "<a href='www.stackoverflow.com'>stackoverflow.com</a>";
$tcpdf = new TCPDF();
$tcpdf->writeHTML($html);
$tcpdf-Output('output.pdf', 'F');

Upvotes: 9

Views: 16696

Answers (3)

Matheus Vicente
Matheus Vicente

Reputation: 1

I tried the solution suggested by Some Guy and it worked for me. Using:

$html = '<a href="www.stackoverflow.com">stackoverflow.com</a>';

Instead of:

$html = "<a href='www.stackoverflow.com'>stackoverflow.com</a>";

Upvotes: 0

Some Guy
Some Guy

Reputation: 11

I believe tcpdf has a problem with single quotes vs double quotes.

You wrote:

$html = "<a href='www.stackoverflow.com'>stackoverflow.com</a>";

I think if you did it this way it would work:

$html = '<a href="www.stackoverflow.com">stackoverflow.com</a>';

Upvotes: 1

Oldskool
Oldskool

Reputation: 34877

As per the documentation, you can use the Write() method on your TCPDF object to achieve this. For example:

$tcpdf->Write(10, 'Google', 'http://www.google.com/', false, 'L', true);

Would write a line with the text Google (left-aligned and with a line break, just added for a better example).

Upvotes: 13

Related Questions