0

I am using TCPDF and getting content from a MySQL table row which is holding HTML like:

<p><a href="x.html"><img src="http://1/2/3/x.jpg" width="x" height="x"></a></p>

The PDF will launch if I surround the IMG SRC tag with single quotes rather than double but the image is not displaying in the PDF.

THe PDF is being generated from a query in the head of the TCPDF document the query in question is:

$query =  "SELECT * FROM solutions WHERE soln_solutionid = $_GET[id]";
$result = mysql_query($query);
$solution = mysql_fetch_array($result);

and the variable is:

$solution['soln_description']

ANy ideas I am banging my head with this one and the TCPDF help and forums are useless!

Thanks

Justin

Justin Erswell
  • 688
  • 7
  • 42
  • 87

1 Answers1

1

TCPDF cannot display images which are on remote servers, you will need to download the image and host it locally on the server to have it included in the PDF output.

See this question on saving an image using CURL in PHP, then simply alter to

<p><a href="x.html"><img src="mylocalpath/x.jpg" width="x" height="x"></a></p>
Community
  • 1
  • 1
Peter Brooks
  • 1,170
  • 9
  • 23
  • Hi thanks for your response, the image is on the local server however it is held outside of the TCPDF directory, which has cause issues with other places that the image is needed and the image is inside the MySQL table row with a bunch of other stuff – Justin Erswell Dec 09 '11 at 10:04
  • this is the url of the example I am working on you will see I have set the URL to the image to be local in the database http://www.testpit.co.uk/orbis/viewArticle.php?id=20 – Justin Erswell Dec 09 '11 at 10:08
  • Give the above solution a try, but you should be able to provide a path to the local file. It's just the HTTP it can't handle. You could even download the file to a temporary path if required. – Peter Brooks Dec 09 '11 at 10:10
  • Thanks Peter but this looks as if it needs a specific image and I don't have that as there maybe multiple images in the table row HTML – Justin Erswell Dec 09 '11 at 10:22
  • How so? Maybe a bit more detail about your problem and I'll try and suggest a solution. – Peter Brooks Dec 09 '11 at 10:52
  • I have a similar issue, I have a variable $output which is $output.="some things heresome things here"; but the images do not get displayed in fact it displays the first line and nothing else, if I remove the images everything else is shown. Every image is hosted localy but nothing ... – JohnnyD Sep 26 '20 at 16:21