【问题标题】:File upload preview image for .doc,.pdf.doc、.pdf 的文件上传预览图像
【发布时间】:2023-03-31 08:27:02
【问题描述】:

在drupal中,当我上传.doc,.pdf文件时,我需要在上传后显示整个文档的预览,请问我知道答案吗

【问题讨论】:

    标签: drupal file-upload


    【解决方案1】:

    我已经用 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);
    }
    

    阅读本文了解更多信息: http://www.lampdeveloper.co.uk/linux/converting-doc-to-pdf-txt-or-html-using-php-and-linux.html

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 2013-06-25
      • 2021-04-06
      • 2013-12-02
      • 2014-12-25
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      相关资源
      最近更新 更多