/** * Un-filter a stream object * * @param array $obj * @return string * @throws Exception */ protected function _unFilterStream($obj) { $filters = array(); if (isset($obj[1][1]['/Filter'])) { $filter = $obj[1][1]['/Filter']; if ($filter[0] == pdf_parser::TYPE_OBJREF) { $tmpFilter = $this->resolveObject($filter); $filter = $tmpFilter[1]; } if ($filter[0] == pdf_parser::TYPE_TOKEN) { $filters[] = $filter; } else { if ($filter[0] == pdf_parser::TYPE_ARRAY) { $filters = $filter[1]; } } } $stream = $obj[2][1]; foreach ($filters as $filter) { switch ($filter[1]) { case '/FlateDecode': case '/Fl': if (function_exists('gzuncompress')) { $oStream = $stream; $stream = strlen($stream) > 0 ? @gzuncompress($stream) : ''; } else { throw new Exception(sprintf('To handle %s filter, please compile php with zlib support.', $filter[1])); } if ($stream === false) { $tries = 0; while ($tries < 8 && ($stream === false || strlen($stream) < strlen($oStream))) { $oStream = substr($oStream, 1); $stream = @gzinflate($oStream); $tries++; } if ($stream === false) { throw new Exception('Error while decompressing stream.'); } } break; case '/LZWDecode': require_once 'filters/FilterLZW.php'; $decoder = new FilterLZW(); $stream = $decoder->decode($stream); break; case '/ASCII85Decode': require_once 'filters/FilterASCII85.php'; $decoder = new FilterASCII85(); $stream = $decoder->decode($stream); break; case '/ASCIIHexDecode': require_once 'filters/FilterASCIIHexDecode.php'; $decoder = new FilterASCIIHexDecode(); $stream = $decoder->decode($stream); break; case null: break; default: throw new Exception(sprintf('Unsupported Filter: %s', $filter[1])); } } return $stream; }
/** * 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->fpdi->error(sprintf("To handle %s filter, please compile php with zlib support.", $_filter[1])); } if ($stream === false) { $this->fpdi->error("Error while decompressing stream."); } break; // mPDF 4.2.003 // mPDF 4.2.003 case '/LZWDecode': include_once _MPDF_PATH . 'mpdfi/filters/FilterLZW.php'; // mPDF 5.0 Removed pass by reference =& $decoder = new FilterLZW(); $stream = $decoder->decode($stream); break; case '/ASCII85Decode': include_once _MPDF_PATH . 'mpdfi/filters/FilterASCII85.php'; // mPDF 5.0 Removed pass by reference =& $decoder = new FilterASCII85(); $stream = $decoder->decode($stream); break; case null: $stream = $stream; break; default: $this->fpdi->error(sprintf("Unsupported Filter: %s", $_filter[1])); } } return $stream; }