- Timestamp:
- 2010/12/11 12:15:20 (13 years ago)
- Location:
- branches/version-2_5-dev/data/module/fpdf
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/module/fpdf/fpdi_pdf_parser.php
r18701 r19716 1 1 <?php 2 2 // 3 // FPDI - Version 1. 24 // 5 // Copyright 2004-20 07Setasign - Jan Slabon3 // FPDI - Version 1.4 4 // 5 // Copyright 2004-2010 Setasign - Jan Slabon 6 6 // 7 7 // Licensed under the Apache License, Version 2.0 (the "License"); … … 18 18 // 19 19 20 require_once( "pdf_parser.php");20 require_once('pdf_parser.php'); 21 21 22 22 class fpdi_pdf_parser extends pdf_parser { … … 59 59 * @var array 60 60 */ 61 var $availableBoxes = array( "/MediaBox","/CropBox","/BleedBox","/TrimBox","/ArtBox");61 var $availableBoxes = array('/MediaBox', '/CropBox', '/BleedBox', '/TrimBox', '/ArtBox'); 62 62 63 63 /** … … 67 67 * @param object $fpdi Object of type fpdi 68 68 */ 69 function fpdi_pdf_parser($filename, &$fpdi) {69 function fpdi_pdf_parser($filename, &$fpdi) { 70 70 $this->fpdi =& $fpdi; 71 $this->filename = $filename;72 71 73 72 parent::pdf_parser($filename); … … 111 110 112 111 if ($pageno < 0 || $pageno >= $this->getPageCount()) { 113 $this->fpdi->error( "Pagenumber is wrong!");112 $this->fpdi->error('Pagenumber is wrong!'); 114 113 } 115 114 … … 164 163 */ 165 164 function getContent() { 166 $buffer = "";165 $buffer = ''; 167 166 168 167 if (isset($this->pages[$this->pageno][1][1]['/Contents'])) { 169 168 $contents = $this->_getPageContent($this->pages[$this->pageno][1][1]['/Contents']); 170 169 foreach($contents AS $tmp_content) { 171 $buffer .= $this->_rebuildContentStream($tmp_content) .' ';170 $buffer .= $this->_rebuildContentStream($tmp_content) . ' '; 172 171 } 173 172 } … … 215 214 $_filter = $obj[1][1]['/Filter']; 216 215 216 if ($_filter[0] == PDF_TYPE_OBJREF) { 217 $tmpFilter = $this->pdf_resolve_object($this->c, $_filter); 218 $_filter = $tmpFilter[1]; 219 } 220 217 221 if ($_filter[0] == PDF_TYPE_TOKEN) { 218 222 $filters[] = $_filter; … … 226 230 foreach ($filters AS $_filter) { 227 231 switch ($_filter[1]) { 228 case "/FlateDecode": 229 if (function_exists('gzuncompress')) { 230 $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; 232 case '/FlateDecode': 233 // $stream .= "\x0F\x0D"; // in an errorious stream this suffix could work 234 if (function_exists('gzuncompress')) { 235 $stream = (strlen($stream) > 0) ? @gzuncompress($stream) : ''; 231 236 } else { 232 $this-> fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.",$_filter[1]));237 $this->error(sprintf('To handle %s filter, please compile php with zlib support.',$_filter[1])); 233 238 } 239 234 240 if ($stream === false) { 235 $this->fpdi->error("Error while decompressing stream.");241 $this->error('Error while decompressing stream.'); 236 242 } 237 243 break; 244 case '/LZWDecode': 245 include_once('filters/FilterLZW_FPDI.php'); 246 $decoder = new FilterLZW_FPDI($this->fpdi); 247 $stream = $decoder->decode($stream); 248 break; 249 case '/ASCII85Decode': 250 include_once('filters/FilterASCII85_FPDI.php'); 251 $decoder = new FilterASCII85_FPDI($this->fpdi); 252 $stream = $decoder->decode($stream); 253 break; 238 254 case null: 239 255 $stream = $stream; 240 256 break; 241 257 default: 242 if (preg_match("/^\/[a-z85]*$/i", $_filter[1], $filterName) && @include_once('decoders'.$_filter[1].'.php')) { 243 $filterName = substr($_filter[1],1); 244 if (class_exists($filterName)) { 245 $decoder =& new $filterName($this->fpdi); 246 $stream = $decoder->decode(trim($stream)); 247 } else { 248 $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); 249 } 250 } else { 251 $this->fpdi->error(sprintf("Unsupported Filter: %s",$_filter[1])); 252 } 258 $this->error(sprintf('Unsupported Filter: %s',$_filter[1])); 253 259 } 254 260 } … … 264 270 * @param array $page a /Page 265 271 * @param string $box_index Type of Box @see $availableBoxes 266 * @return array 267 */ 268 function getPageBox($page, $box_index) { 269 $page = $this->pdf_resolve_object($this->c,$page); 272 * @param float Scale factor from user space units to points 273 * @return array 274 */ 275 function getPageBox($page, $box_index, $k) { 276 $page = $this->pdf_resolve_object($this->c, $page); 270 277 $box = null; 271 278 if (isset($page[1][1][$box_index])) … … 273 280 274 281 if (!is_null($box) && $box[0] == PDF_TYPE_OBJREF) { 275 $tmp_box = $this->pdf_resolve_object($this->c, $box);282 $tmp_box = $this->pdf_resolve_object($this->c, $box); 276 283 $box = $tmp_box[1]; 277 284 } … … 279 286 if (!is_null($box) && $box[0] == PDF_TYPE_ARRAY) { 280 287 $b =& $box[1]; 281 return array("x" => $b[0][1]/$this->fpdi->k, 282 "y" => $b[1][1]/$this->fpdi->k, 283 "w" => abs($b[0][1]-$b[2][1])/$this->fpdi->k, 284 "h" => abs($b[1][1]-$b[3][1])/$this->fpdi->k); 288 return array('x' => $b[0][1]/$k, 289 'y' => $b[1][1]/$k, 290 'w' => abs($b[0][1]-$b[2][1])/$k, 291 'h' => abs($b[1][1]-$b[3][1])/$k, 292 'llx' => min($b[0][1], $b[2][1])/$k, 293 'lly' => min($b[1][1], $b[3][1])/$k, 294 'urx' => max($b[0][1], $b[2][1])/$k, 295 'ury' => max($b[1][1], $b[3][1])/$k, 296 ); 285 297 } else if (!isset ($page[1][1]['/Parent'])) { 286 298 return false; 287 299 } else { 288 return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index); 289 } 290 } 291 292 function getPageBoxes($pageno) { 293 return $this->_getPageBoxes($this->pages[$pageno-1]); 294 } 295 296 /** 297 * Get all Boxes from /Page 300 return $this->getPageBox($this->pdf_resolve_object($this->c, $page[1][1]['/Parent']), $box_index, $k); 301 } 302 } 303 304 /** 305 * Get all page boxes by page no 306 * 307 * @param int The page number 308 * @param float Scale factor from user space units to points 309 * @return array 310 */ 311 function getPageBoxes($pageno, $k) { 312 return $this->_getPageBoxes($this->pages[$pageno-1], $k); 313 } 314 315 /** 316 * Get all boxes from /Page 298 317 * 299 318 * @param array a /Page 300 319 * @return array 301 320 */ 302 function _getPageBoxes($page ) {321 function _getPageBoxes($page, $k) { 303 322 $boxes = array(); 304 323 305 324 foreach($this->availableBoxes AS $box) { 306 if ($_box = $this->getPageBox($page, $box)) {325 if ($_box = $this->getPageBox($page, $box, $k)) { 307 326 $boxes[$box] = $_box; 308 327 } … … 312 331 } 313 332 333 /** 334 * Get the page rotation by pageno 335 * 336 * @param integer $pageno 337 * @return array 338 */ 314 339 function getPageRotation($pageno) { 315 340 return $this->_getPageRotation($this->pages[$pageno-1]); 316 341 } 317 342 318 function _getPageRotation 343 function _getPageRotation($obj) { // $obj = /Page 319 344 $obj = $this->pdf_resolve_object($this->c, $obj); 320 345 if (isset ($obj[1][1]['/Rotate'])) { … … 342 367 * @param array the result-array 343 368 */ 344 function read_pages 369 function read_pages(&$c, &$pages, &$result) { 345 370 // Get the kids dictionary 346 $kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); 347 348 if (!is_array($kids)) 349 $this->fpdi->Error("Cannot find /Kids in current /Page-Dictionary"); 350 foreach ($kids[1] as $v) { 371 $_kids = $this->pdf_resolve_object ($c, $pages[1][1]['/Kids']); 372 373 if (!is_array($_kids)) 374 $this->error('Cannot find /Kids in current /Page-Dictionary'); 375 376 if ($_kids[1][0] == PDF_TYPE_ARRAY) { 377 $kids = $_kids[1][1]; 378 } else { 379 $kids = $_kids[1]; 380 } 381 382 foreach ($kids as $v) { 351 383 $pg = $this->pdf_resolve_object ($c, $v); 352 384 if ($pg[1][1]['/Type'][1] === '/Pages') { 353 385 // If one of the kids is an embedded 354 386 // /Pages array, resolve it as well. 355 $this->read_pages 387 $this->read_pages($c, $pg, $result); 356 388 } else { 357 389 $result[] = $pg; … … 369 401 function getPDFVersion() { 370 402 parent::getPDFVersion(); 371 372 if (isset($this->fpdi->importVersion) && $this->pdfVersion > $this->fpdi->importVersion) { 373 $this->fpdi->importVersion = $this->pdfVersion; 374 } 403 $this->fpdi->setPDFVersion(max($this->fpdi->getPDFVersion(), $this->pdfVersion)); 375 404 } 376 405 377 406 } 378 379 ?>
Note: See TracChangeset
for help on using the changeset viewer.