阅读和检查PDF文件


Reading and checking PDF Files

我正在尝试以下操作:我想打开一个现有的PDF文档,并检查其中每一页的宽度。

$pdf = Zend_Pdf::Load( $fullFilePath );      
foreach($pdf->pages As $key => $page)
{
  $width  = $page->getWidth();
}

但我每次都有同样的宽度。即使有"双页"(要理解我的意思,请参阅http://www.reinkesupply.com/Acoustical%20Cross-参考.pdf)

我还有一个问题。我也希望使用交叉引用PDF。任何人都可以给我任何提示,我应该做些什么来达到目标?如前所述,我只需要打开PDF文件并检查页面宽度。

在检查一些待办事项时,我得到了以下错误:

Message:
PDF file syntax error. Offset - 0x12E9048. Wrong W dictionary entry. Only type field of stream entries has default value and could be zero length.
Stack trace:
#0 C:'xampp'htdocs'qs'library'Zend'Pdf'Parser.php(455): Zend_Pdf_Parser->_loadXRefTable('19828808')
#1 C:'xampp'htdocs'qs'library'Zend'Pdf.php(297): Zend_Pdf_Parser->__construct('C:'xampp'htdocs...', Object(Zend_Pdf_ElementFactory_Proxy), true)
#2 C:'xampp'htdocs'qs'library'Zend'Pdf.php(250): Zend_Pdf->__construct('C:'xampp'htdocs...', NULL, true)
#3 C:'xampp'htdocs'qs'application'controllers'IndexController.php(18): Zend_Pdf::load('C:'xampp'htdocs...')
#4 C:'xampp'htdocs'qs'library'Zend'Controller'Action.php(503): IndexController->indexAction()
#5 C:'xampp'htdocs'qs'library'Zend'Controller'Dispatcher'Standard.php(285): Zend_Controller_Action->dispatch('indexAction')
#6 C:'xampp'htdocs'qs'library'Zend'Controller'Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#7 C:'xampp'htdocs'qs'public'index.php(24): Zend_Controller_Front->dispatch()
#8 {main}

我想这是因为相互参照。我说得对吗?有什么简单的方法可以修理它吗?

感谢

基本问题是Zend_Pdf_Page使用Media Box属性来计算每页的宽度和高度,而不是(在这种特殊情况下)Crop Box。有关各种框的进一步说明,请参阅此链接:http://www.prepressure.com/pdf/basics/page_boxes

在您的情况下,一个可能的解决方案是修补Zend_Pdf_Page,使其在可用时使用Crop Box值,否则返回Media Box值。代码在getHeight()getWidth()方法中,它们从ZF 1.1.11中的第459行开始。

然而,我没有足够的经验来判断永久使用Crop Box是否是个好主意。也许其他人可以对此发表评论?我从前面提到的链接中得到的印象是,Trim Box可能是一个更好的选择,但我不认为你提到的PDF样本包含这些数据。

你是否相信Zend_Pdf_Page的当前行为是正确的,实际上取决于定义。你想要整个画布的大小,比如一张稍后可能会进行物理修剪的纸(你可能想知道这一点,这样你就可以在页面的非打印部分添加注释),还是你通常希望在屏幕上看到的可视区域?正确的答案可能是两者都有:Zend_Pdf_Page可能需要更多的方法,或者至少需要在getWidth()getHeight()中添加一个参数,使调用方能够准确地指定他们感兴趣的维度。我快速查看了ZF问题跟踪器,但找不到任何相关信息,所以我将添加一个票证。至少doc块应该提到它返回Media Box的大小,并鼓励用户理解这意味着什么。

最终,如果我是你,我可能会进去修补Zend_Pdf_Page,这样当Crop Box可用时,它会返回该大小,否则它会返回Media Box。如果你想贡献这个补丁,你的旅程从这里开始:http://framework.zend.com/wiki/display/ZFDEV/Contributing+到+Zend+框架:-)