I try to upload a pdf in a site. My link works fine, the pdf file loads without problem. Right below my link I need a preview of the file as an image. There is an error with the preview, nothing shows in my boxed area.
<a href="<?php echo $pdf; ?> "PDF: ?php echo "$title"; ?>
<img src="<?php echo "$pdf"; ?> " WIDTH="98%" border="1" title="<?php echo "$title"; ?> " caption="Click here to load PDF" /></a>
A PDF is not an image. You need to convert it to an image to display it in an img tag. You can do this using PHP's built in ImageMagick functions
Edit: Here is a quick code sample:
$imagick = new Imagick();
try {
$imagick->readImage($filename);
$imagick->setIteratorIndex($page_num);
$imagick->thumbnailImage($width, $height);
$imagick->setFormat('jpeg');
// For Base64 Inline Thumbnail
$img_src = 'data:image/jpeg;base64,'.base64_encode((string)$imagick);
}
catch(ImagickException $ImagickException){
// Handle Error, probably bad file
}
Then put $img_src as the image source for your image tag.
You can't preview pdf with img tag and without an external pdf viewer like these pdf viewer
but do you really need??