Drupal 文件上载.doc、.pdf的预览图像
在drupal中,当我上传.doc、.pdf文件时,我需要在上传后显示整个文档的预览。我可以知道答案吗?我已经用php解决了这个问题,下面是我编写的函数: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
//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);
}