开发者

Create and display PDF thumbnail using ImageMagick and jQuery

I have a 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 PDF 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?


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);
    }
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜