tcpdf writeHTML why are my links not getting included (html to pdf conversion)

Well I know this one because I spent almost an hour just to fix it and I was embarrassed when i realized the solution was so simple

Two things that are most important when you are using tcpdf for converting HTML to PDF are

  1. Valid HTML
  2. Values you passed to the tcpdf functions should be totally understood and you should know what they does

ok lets see what the problem is with link

In my case

if you have a php string like

  1. $html = "<a href='http://jaspreetchahal.org'>jaspreetchahal.org</a>";

above is valid string but somehow tcpdf with not take single quotes with great pleasure and you will see that even though It will colour “jaspreetchahal.org” part of anchor, when you try to click on that link it takes you nowhere

now the solution

  1. $html = '<a href="http://jaspreetchahal.org">jaspreetchahal.org</a>'; 
  2.  
  3. OR
  4. $html =<<<LINK
  5. <a href="http://jaspreetchahal.org">jaspreetchahal.org</a>
  6. LINK;

Just replace single quote with double quotes and vice versa and you’re done

A clickable link :)

 

Hope this helps

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Comments

  1. Your solution does not wor for me.
    I can’t see any Anchors in my output pdf anyway.

    However I found out that using sigle quotes i can display them, at least ( if not using them because are not clickable).
    And I am displaying the anchors with href in single quotes and with preg_replace i am adding the href attribute content inside anchor tag. This way i display the link and the url.
    It is not so pretty but a solution.

  2. I thought I found the answer cause my links are also not displayed but it seems that my problem is with very long text in urls. Any solution for that?

  3. Thank you so very much! I spent embarrassingly longer than an hour – on trying to get images working – and couldn’t find a fix until I found this.

Speak Your Mind

*

CommentLuv badge