Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Drupal 文件上载.doc、.pdf的预览图像_Drupal_File Upload - Fatal编程技术网

Drupal 文件上载.doc、.pdf的预览图像

Drupal 文件上载.doc、.pdf的预览图像,drupal,file-upload,Drupal,File Upload,在drupal中,当我上传.doc、.pdf文件时,我需要在上传后显示整个文档的预览。我可以知道答案吗?我已经用php解决了这个问题,下面是我编写的函数: //requires imagemagick which is on most servers function thumbFromPDF($path, $page=0){ $im = new imagick($path.'['.$page.']'); $im->setImageFormat('png'); $im->write

在drupal中,当我上传.doc、.pdf文件时,我需要在上传后显示整个文档的预览。我可以知道答案吗?我已经用php解决了这个问题,下面是我编写的函数:

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