从php/linux获取pdf的布局模式(横向或纵向) [英] Get the layout mode (landscape or portrait) of a pdf from php/linux

查看:293
本文介绍了从php/linux获取pdf的布局模式(横向或纵向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出PDF,如何使用PHP lib或linux命令行工具获得PDF的布局模式(或相对宽度/高度)?

使用 http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp = tcpdf ,它可以在新的PDF上设置此变量,但对于Adobe的现有pdf可以设置.

应该将pdf转换为ps,或以其他方式使用gs-例如先将其转换为图像,然后获取其宽度和高度.这是最好的方法吗?

解决方案

我正在使用的解决方案是使用ghostscript将第一页打印到图像上,然后获取图像尺寸

$cmd = 'gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sDEVICE=png16m -r400 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="'.$complete_file_path.'/p%d.png" "'.$complete_file_path.'/'.$this->pdffilename.'"';
        $result = $this->proc( $cmd );
        list($width, $height, $type, $attr) = getimagesize($complete_file_path.'/'.$pngfilename);

Given a PDF, how can one get the layout mode of a PDF (or relative width/height) using a PHP lib or linux command line tool?

Using http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf which can set this variable on new PDFs, but for existing pdfs from adobe.

Thought of converting pdfs to ps, or using gs in some other way - like converting it to an image first, and getting the width and height of that. Is this the best way?

解决方案

The solution I'm using is to use ghostscript to print the first page to an image, then getting the image dimensions

$cmd = 'gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sDEVICE=png16m -r400 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sOutputFile="'.$complete_file_path.'/p%d.png" "'.$complete_file_path.'/'.$this->pdffilename.'"';
        $result = $this->proc( $cmd );
        list($width, $height, $type, $attr) = getimagesize($complete_file_path.'/'.$pngfilename);

这篇关于从php/linux获取pdf的布局模式(横向或纵向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆