tcpdf-laravel: tcpdf.php throws error if HTML has 2 HREFs in it
I am using Laravel 5.3 and the current version of this wrapper. Not sure if this is an error in this wrapper, or the underlying library for tcpdf. But I think it is this wrapper because I am converting a static app to laravel and tcpdf works in my static app, and also, the tcpdf example pages have html data with multiple links in it.
I have now tested this in many ways, and if I have HTML data to convert to pdf that has 2 links in the data e.g. something like this:
<p>Lorem ipsum dolor sit amet <a href="http://www.somelink.com/">link</a>
consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua <a href="http://www.somelink2.com/">link2</a> etc...</p>
I always get a failure throwing the error: ErrorException in tcpdf.php line 18807: Illegal string offset 'url'
But, if I have HTML data with just one href link in it, the PDF resolves fine.
Line 18807 in tcpdf.php is:
$this->HREF['url'] = $tag['attribute']['href'];
The code near there in tcpdf.php is:
case 'a': {
if (array_key_exists('href', $tag['attribute'])) {
$this->HREF['url'] = $tag['attribute']['href'];
}
break;
}
I do not think this will matter, but my PDF generating code (sans the actual html) is:
PDF::SetTitle('Title of PDF');
PDF::SetFont('times', '', 11);
PDF::AddPage();
$image = public_path().'/images/logo.jpg';
PDF::Image($image,
$x = '10',
$y = '10',
$w = 75,
$h = 0,
$type = 'JPG',
$link = '',
$align = 'N',
$resize = false,
$dpi = 300,
$palign = 'L',
$ismask = false,
$imgmask = false,
$border = 0,
$fitbox = false,
$hidden = false,
$fitonpage = false,
$alt = false,
$altimgs = array());
PDF::WriteHTML($docbody);
PDF::writeHTMLCell(120, 0, '', '', $html, '', 1, 0, true, 'R', true);
$attachment = storage_path().'/filelocation/'.$var->name.'_'.date("F j, Y").'.pdf';
PDF::Output($attachment,'FI');
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (7 by maintainers)
There seems to be another place in the code where an empty string has been assigned to $this->HREF. I made the following change and it seems to solve the problem.
On line 19756:
case ‘a’: { $this->HREF = []; // 2020-05-15 changed ‘’ to empty array [] break; }
@elibyy it did… I did not realize I had downloaded an older version after going through the docs. Thank you!
Hey @paoga87 You should update your tecnickcom/TCPDF to the latest version and that should fix the issue. Please let me know if that solved the problem.
Eli
Came across this problem while using TCPDF with WordPress, so for the record I think this is a TCPDF problem and specific to PHP 7.0 or 7.1 (I don’t get it in 5.6). TCPDF is no longer receiving updates, but it’s replacement tc-pdf is not ready yet.