在做一个OA系统项目中,开发到传真模块,传真数据是通过aofax收发的,现在要把收到的tif文档显示到浏览器上。最好的办法是把tif文档转换成pdf的格式。步骤如下:1、运行以下五条代码sudo aptitude updatesudo aptitude install make php5-cli php5-gd php5-dev php-pear gs-common ghostscriptsudo aptitude remove php5-imagicksudo apt-get install libmagick9-devsudo pecl install imagick //如果只安装这个会出问题就把上面四个都安装了2、在/etc/php5/apache/php.ini中加入extension=imagick.so扩展3、重启apache,/etc/init.d/apache restart以上配置完后测试调用这个函数
- private function tif_to_pdf($file_tif,$file_pdf){
- $errors = array();
- $cmd_ps2pdf = "/usr/bin/ps2pdfwr";
- // $file_tif = escapeshellarg($file_tif);//escapeshellarg函数用于过滤shell参数
- // $file_pdf = escapeshellarg($file_pdf);
- if (!file_exists($file_tif)) $errors[] = "Original TIFF file: ".$file_tif." does not exist";
- if (!file_exists($cmd_ps2pdf)) $errors[] = "Ghostscript PostScript to PDF converter not found at: ".$cmd_ps2pdf;
- if (!extension_loaded("imagick")) $errors[] = "Imagick extension not installed or not loaded";
- if (!count($errors)) {
- // 确认文件的基本路径
- $base = $file_pdf;
- if(($ext = strrchr($file_pdf, ".")) !== false) $base = substr($file_pdf, 0, -strlen($ext));
- // Determine the temporary .ps filepath
- $file_ps = $base.".ps";
- // 打开原始的.tiff文件
- $document = new Imagick($file_tif);
- // Use Imagick to write multiple pages to 1 .ps file
- if (!$document->writeImages($file_ps, true)) {
- $errors[] = "Unable to use Imagick to write multiple pages to 1 .ps file: ".$file_ps;
- } else {
- $document->clear();
- // Use ghostscript to convert .ps -> .pdf
- exec($cmd_ps2pdf." -sPAPERSIZE=a4 ".$file_ps." ".$file_pdf, $o, $r);
- if ($r) {
- $errors[] = "Unable to use ghostscript to convert .ps(".$file_ps.") -> .pdf(".$file_pdf."). Check rights. ";
- }
- }
- }
-
- // return array with errors, or true with success.
- if (!count($errors)) {
- return true;
- } else {
- return $errors;
- }
- }
Linux系统下vi编辑器的属性设置在Ubuntu上搭建Pure-ftpd服务相关资讯 Ubuntu基础教程
- 如何在Ubuntu中添加和删除书签 (10/08/2015 11:51:26)
- 如何通过简单的3步恢复Windows 7同 (03/29/2015 16:50:03)
- ldconfig deferred processing now (12/08/2013 16:24:06)
| - 如何在 Ubuntu 中再次登录时还原上 (04/20/2015 21:02:23)
- 让你玩转 Ubuntu 桌面的十一件武器 (03/11/2015 09:30:49)
- Ubuntu基础教程——如何修改你的计 (11/02/2013 06:49:12)
|
本文评论 查看全部评论 (0)