简体   繁体   中英

Create and display pdf thumbnail using imagemagick and jquery

I have the php script to create pdf thumbnail in jpg as follows;

<?php
$pdffile="test.pdf";
$info = pathinfo($pdffile);
$file_name =  basename($pdffile,'.'.$info['extension']);
exec("convert -quality 50 -border 1x1 -density 300 -bordercolor #ffffff -colorspace rgb ".$pdffile."[0] -thumbnail 200x200 ".$file_name.".jpg");
?>

The string $pdffile can be replaced with some $_POST or $_GET to change the pdf file.

What i want is to display the image in web page. If the image with same file name is there, the browser may display the image directly and if the image is not there, the browser may display after creating the image.

I am looking for an ajax solution, The javascript will first send the data to a php file to check if the file exists, and display the image if its there, else will display the image after creating it.

I have a table with 4 columns with 4 different pdfd files. I want to display 4 thumbnails at a time, inside their corresponding columns...

+-----------+-----------+-----------+-----------+
| test1.pdf | test2.pdf | test3.pdf | test4.pdf |
+-----------+-----------+-----------+-----------+

How can i make this possible using jquery??

Thanks in advance... :)

blasteralfred

Setup a server method that does the image generation and returns a path to the javascript. Then update the "src" attribute to point to the path.

$.ajax({
    url: [your url for your method],
    type: ["POST" | "GET"],
    success: function(url){
        $('#ImageId').attr('src',url);
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM