Exemplo n.º 1
0
 /**
  * Rebuild content-streams
  *
  * @param array $obj
  * @return string
  */
 function _rebuildContentStream($obj)
 {
     $filters = array();
     if (isset($obj[1][1]['/Filter'])) {
         $_filter = $obj[1][1]['/Filter'];
         if ($_filter[0] == PDF_TYPE_TOKEN) {
             $filters[] = $_filter;
         } else {
             if ($_filter[0] == PDF_TYPE_ARRAY) {
                 $filters = $_filter[1];
             }
         }
     }
     $stream = $obj[2][1];
     foreach ($filters as $_filter) {
         switch ($_filter[1]) {
             case '/FlateDecode':
                 if (function_exists('gzuncompress')) {
                     $stream = strlen($stream) > 0 ? @gzuncompress($stream) : '';
                 } else {
                     $this->error(sprintf('To handle %s filter, please compile php with zlib support.', $_filter[1]));
                 }
                 if ($stream === false) {
                     $this->error('Error while decompressing stream.');
                 }
                 break;
             case '/LZWDecode':
                 include_once 'filters/FilterLZW_FPDI.php';
                 $decoder = new FilterLZW_FPDI($this->fpdi);
                 $stream = $decoder->decode($stream);
                 break;
             case '/ASCII85Decode':
                 include_once 'filters/FilterASCII85_FPDI.php';
                 $decoder = new FilterASCII85_FPDI($this->fpdi);
                 $stream = $decoder->decode($stream);
                 break;
             case null:
                 $stream = $stream;
                 break;
             default:
                 $this->error(sprintf('Unsupported Filter: %s', $_filter[1]));
         }
     }
     return $stream;
 }
Exemplo n.º 2
0
 /**
  * Rebuild content-streams
  *
  * @param array $obj
  * @return string
  */
 function _rebuildContentStream($obj)
 {
     $filters = array();
     if (isset($obj[1][1]['/Filter'])) {
         $_filter = $obj[1][1]['/Filter'];
         if ($_filter[0] == PDF_TYPE_OBJREF) {
             $tmpFilter = $this->pdf_resolve_object($this->c, $_filter);
             $_filter = $tmpFilter[1];
         }
         if ($_filter[0] == PDF_TYPE_TOKEN) {
             $filters[] = $_filter;
         } elseif ($_filter[0] == PDF_TYPE_ARRAY) {
             $filters = $_filter[1];
         }
     }
     $stream = $obj[2][1];
     foreach ($filters as $_filter) {
         switch ($_filter[1]) {
             case '/FlateDecode':
             case '/Fl':
                 // $stream .= "\x0F\x0D"; // in an errorious stream this suffix could work
                 // $stream .= "\x0A";
                 // $stream .= "\x0D";
                 if (function_exists('gzuncompress')) {
                     $oStream = $stream;
                     $stream = strlen($stream) > 0 ? @gzuncompress($stream) : '';
                 } else {
                     $this->error(sprintf('To handle %s filter, please compile php with zlib support.', $_filter[1]));
                 }
                 if ($stream === false) {
                     $oStream = substr($oStream, 2);
                     $stream = @gzinflate($oStream);
                     if ($stream == false) {
                         $this->error('Error while decompressing stream.');
                     }
                 }
                 break;
             case '/LZWDecode':
                 include_once 'filters/FilterLZW_FPDI.php';
                 $decoder = new FilterLZW_FPDI($this->fpdi);
                 $stream = $decoder->decode($stream);
                 break;
             case '/ASCII85Decode':
                 include_once 'filters/FilterASCII85_FPDI.php';
                 $decoder = new FilterASCII85_FPDI($this->fpdi);
                 $stream = $decoder->decode($stream);
                 break;
             case null:
                 $stream = $stream;
                 break;
             default:
                 $this->error(sprintf('Unsupported Filter: %s', $_filter[1]));
         }
     }
     return $stream;
 }