在禪道中實現WORD等OFFICE文檔轉換爲PDF進行在線瀏覽

條件: php

  1. 安裝好禪道的服務器
  2. 能直接瀏覽PDF的瀏覽器(或經過 安裝插件實現 )
  3. 文檔轉換服務程序(建議部署在另外一臺服務器上)

   

實現 原理: html

  1. 修改禪道的文件預覽功能(OFFICE文檔其使用的是下載打開方式)爲向轉換服務請求PDF
  2. 轉換服務收到URL後,下載該文件並調用後臺服務轉換爲PDF,向請求者返回PDF
  3. 禪道內置的預覽PDF功能直接請求瀏覽器預覽PDF

   

須要修改的文件及內容 web

xampp\zentao\module\file\control.php 瀏覽器

xampp\zentao\module\file\view\printfiles.html.php 服務器

xampp\zentao\module\group\lang\resource.php session

xampp\zentao\module\file\lang\zh-cn.php app

   

control.php this

   

增長方法 url

   

public function cloudview($fileID, $mouse = '') spa

{

$file = $this->file->getById($fileID);

   

/* Judge the mode, down or open. */

$mode = 'view';

$fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html|pdf|dwg';

if(stripos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open';

        if($mode == 'open')

{

if(file_exists($file->realPath))$this->locate($file->webPath);

$this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true);

}

        else

if(file_exists($file->realPath))

{

$fileName = $file->title . '.' . $file->extension;

                $fileData = file_get_contents($file->realPath);

                $md5data=md5( $fileData);

$this->locate( 'http://192.168.118.136:9345/?url=' . common::getSysURL() . $file-> webPath . '&' . 'fileName=' . $fileName . '&' . 'md5=' . $md5data );

}

else

{

$this->app->triggerError("The file you visit $fileID not found.", __FILE__, __LINE__, true);

}

   

}

   

   

printfiles.html.php

   

修改方法downloadFile

新增方法viewFile

增長超連接指向

function downloadFile(fileID)

{

if(!fileID) return;

var sessionString = '<?php echo $sessionString;?>';

var url = createLink('file', 'cloudview', 'mfileID=' + fileID + '&mouse=left&mode=open') + sessionString;

      

window.open(url, '_blank');

return false;

}

   

function viewFile(fileID)

{

if(!fileID) return;

var sessionString = '<?php echo $sessionString;?>';

var url = createLink('file', 'cloudview', 'mfileID=' + fileID + '&mouse=left&mode=open') + sessionString;

        

window.open(url, '_blank');

return false;

}

   

增長連接

   

$fileTitle = "<li class='list-group-item'><i class='icon-file-text text-muted icon'></i> &nbsp;" . $file->title .'.' . $file->extension;

echo html::a($this->createLink('file', 'download', "fileID=$file->id") . $sessionString, $fileTitle, '_blank', "onclick='return viewFile($file->id)'");

echo "<span class='right-icon'>";

         common::printLink('file', 'download', "fileID=$file->id", "<i class='icon-download'></i>", '', "class='edit btn-icon' title='{$lang->file->download}'");

common::printLink('file', 'edit', "fileID=$file->id", "<i class='icon-pencil'></i>", '', "class='edit btn-icon' title='{$lang->file->edit}'");

if(common::hasPriv('file', 'delete')) echo html::a('###', "<i class='icon-remove'></i>", '', "class='btn-icon' onclick='deleteFile($file->id)' title='$lang->delete'");

echo '</span>';

echo '</li>';

   

resource.php

   

$lang->resource->file = new stdclass();

$lang->resource->file->download = 'download';

$lang->resource->file->cloudview = 'cloudview';

$lang->resource->file->edit = 'edit';

   

zh-cn.php

   

$lang->file->uploadImages = '多圖上傳';

$lang->file->cloudview = '雲預覽';

$lang->file->download = '下載附件';

   

   

執行效果

   

權限

   

   

附件管理

 

相關文章
相關標籤/搜索