anand
anand

Reputation: 1

File upload preview image for .doc,.pdf

In drupal when i am uploading a .doc,.pdf files I need to display the preview of the whole document after it get uploaded may i know the answer

Upvotes: 0

Views: 1325

Answers (1)

Landon
Landon

Reputation: 4108

I've solved this issue with php, here are the functions that I wrote:

//requires imagemagick which is on most servers
function thumbFromPDF($path, $page=0){
$im = new imagick($path.'['.$page.']'); 
$im->setImageFormat('png');
$im->writeImage( '/tmp/img.png' );
$im=imagecreatefrompng('/tmp/img.png');
return $im;

}

function thumbFromDoc($path, $page=0){
$cmd='unoconv --server localhost --port 2002 --stdout -f pdf '.$path;//-f could be pdf, txt, or html
$pdf = shell_exec ( $cmd );  

$outfilefile='/tmp/pdf.pdf';
if (! $handle = fopen ( $outfilefile, 'w' )) {  
    die("Cannot open file ($outfilefile)");  
    return false;
}  

// Write $somecontent to our opened file.  
if (fwrite ( $handle, $pdf ) === FALSE) {  
    die("Cannot write to file ($location$file)");  
    return false;  
}  

fclose ( $handle );  
return thumbFromPDF($outfilefile,$page);
}

Read this article for more information: http://www.lampdeveloper.co.uk/linux/converting-doc-to-pdf-txt-or-html-using-php-and-linux.html

Upvotes: 1

Related Questions