简体   繁体   中英

Reading and checking PDF Files

I'm trying the following: I want to open an existing PDF Document and check the width of every page in it.

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

But I'm getting same width every time. Even if there are "double pages" (to understand what i mean see http://www.reinkesupply.com/Acoustical%20Cross-Reference.pdf )

I have one more question. I wish to do it with cross - reference PDFs too. Anyone could give me any hint what should i fix to reach the goal? As already mentioned i only wat to open PDF file and check the page width.

While checking few dos I'm getting the following error:

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}

I suppose this is because of cross reference. Am I right? Is there any easy way to fix it?

Thanks

The basic problem is that Zend_Pdf_Page is using the Media Box attributes to calculate the width and height of each page, rather than (in this particular case) the Crop Box. For further explanation of the various boxes, see this link: http://www.prepressure.com/pdf/basics/page_boxes

One possible solution in your case would be to patch Zend_Pdf_Page so that it uses the Crop Box values when available, otherwise it returns the Media Box values. The code is in the getHeight() and getWidth() methods, which start at around line 459 in ZF 1.1.11.

However, I am not experienced enough to say whether using Crop Box permanently is a good idea or not. Perhaps somebody else can comment on this? The impression I got from the aforementioned link is that Trim Box might be a better option, but I don't think the sample PDF you referred to contains that data.

Whether or not you believe that the current behavior of Zend_Pdf_Page is correct or not really depends on definitions. Do you want the size of the whole canvas, ie. a piece of paper that you might later physically trim (you might want to know this so that you can add notes to part of the page that is not intended for printing), or the viewable area that you would normally expect to see on the screen? The correct answer is probably both: Zend_Pdf_Page probably needs more methods, or at least a parameter added to getWidth() and getHeight() that allows the caller to specify exactly which dimensions they're interested in. I had a quick look on the ZF issue tracker and couldn't find anything about this, so I will add a ticket. At the very least the doc block should mention that it returns the size of the Media Box and encourage users to understand what that means.

Ultimately, if I were you, I would probably go in and patch Zend_Pdf_Page so that when Crop Box is available it returns that size, otherwise it returns Media Box. And if you want to contribute that patch, your journey starts here: http://framework.zend.com/wiki/display/ZFDEV/Contributing+to+Zend+Framework :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM