44 require_once(dirname(__FILE__).
'/tcpdf_filters.php');
60 private $pdfdata =
'';
78 private $FilterDecoders;
90 $this->
Error(
'Empty PDF data.');
92 $this->pdfdata =
$data;
94 $pdflen = strlen($this->pdfdata);
100 $this->objects = array();
101 foreach ($this->xref[
'xref'] as $obj => $offset) {
102 if (!isset($this->objects[$obj])) {
107 unset($this->pdfdata);
118 return array($this->xref, $this->objects);
132 if (preg_match_all(
'/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_SET_ORDER, $offset) == 0) {
133 $this->
Error(
'Unable to find startxref');
135 $matches = array_pop($matches);
136 $startxref = $matches[1];
139 if (preg_match(
'/[\r\n]startxref[\s]*[\r\n]+([0-9]+)[\s]*[\r\n]+%%EOF/i', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) == 0) {
140 $this->
Error(
'Unable to find startxref');
142 $startxref = $matches[1][0];
145 if (strpos($this->pdfdata,
'xref', $startxref) != $startxref) {
146 $this->
Error(
'Unable to find xref');
149 $xoffset = $startxref + 5;
153 while (preg_match(
'/^([0-9]+)[\s]([0-9]+)[\s]?([nf]?)/im', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $offset) > 0) {
154 $offset = (strlen($matches[0][0]) + $matches[0][1]);
155 if ($matches[3][0] ==
'n') {
157 $index = $obj_num.
'_'.intval($matches[2][0]);
159 if (!isset(
$xref[
'xref'][$index])) {
161 $xref[
'xref'][$index] = intval($matches[1][0]);
165 }
elseif ($matches[3][0] ==
'f') {
170 $obj_num = intval($matches[1][0]);
174 if (preg_match(
'/trailer[\s]*<<(.*)>>[\s]*[\r\n]+startxref[\s]*[\r\n]+/isU', $this->pdfdata, $matches, PREG_OFFSET_CAPTURE, $xoffset) > 0) {
175 $trailer_data = $matches[1][0];
176 if (!isset(
$xref[
'trailer'])) {
178 $xref[
'trailer'] = array();
180 if (preg_match(
'/Size[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
181 $xref[
'trailer'][
'size'] = intval($matches[1]);
183 if (preg_match(
'/Root[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
184 $xref[
'trailer'][
'root'] = intval($matches[1]).
'_'.intval($matches[2]);
186 if (preg_match(
'/Encrypt[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
187 $xref[
'trailer'][
'encrypt'] = intval($matches[1]).
'_'.intval($matches[2]);
189 if (preg_match(
'/Info[\s]+([0-9]+)[\s]+([0-9]+)[\s]+R/i', $trailer_data, $matches) > 0) {
190 $xref[
'trailer'][
'info'] = intval($matches[1]).
'_'.intval($matches[2]);
192 if (preg_match(
'/ID[\s]*[\[][\s]*[<]([^>]*)[>][\s]*[<]([^>]*)[>]/i', $trailer_data, $matches) > 0) {
193 $xref[
'trailer'][
'id'] = array();
194 $xref[
'trailer'][
'id'][0] = $matches[1];
195 $xref[
'trailer'][
'id'][1] = $matches[2];
198 if (preg_match(
'/Prev[\s]+([0-9]+)/i', $trailer_data, $matches) > 0) {
203 $this->
Error(
'Unable to find trailer');
219 $offset += strspn($this->pdfdata,
"\x00\x09\x0a\x0c\x0d\x20", $offset);
221 $char = $this->pdfdata{$offset};
226 $next = strcspn($this->pdfdata,
"\r\n", $offset);
237 if (preg_match(
'/^([^\x00\x09\x0a\x0c\x0d\x20\s\x28\x29\x3c\x3e\x5b\x5d\x7b\x7d\x2f\x25]+)/', substr($this->pdfdata, $offset, 256), $matches) == 1) {
238 $objval = $matches[1];
239 $offset += strlen($objval);
251 while ($open_bracket > 0) {
252 if (!isset($this->pdfdata{$strpos})) {
255 $ch = $this->pdfdata{$strpos};
273 $objval = substr($this->pdfdata, $offset, ($strpos - $offset - 1));
289 $offset = $element[2];
290 $objval[] = $element;
291 }
while ($element[0] !=
']');
299 if (isset($this->pdfdata{($offset + 1)}) AND ($this->pdfdata{($offset + 1)} == $char)) {
301 $objtype = $char.$char;
309 $offset = $element[2];
310 $objval[] = $element;
311 }
while ($element[0] !=
'>>');
319 if (($char ==
'<') AND (preg_match(
'/^([0-9A-Fa-f]+)[>]/iU', substr($this->pdfdata, $offset), $matches) == 1)) {
320 $objval = $matches[1];
321 $offset += strlen($matches[0]);
327 if (substr($this->pdfdata, $offset, 6) ==
'endobj') {
331 }
elseif (substr($this->pdfdata, $offset, 4) ==
'null') {
336 }
elseif (substr($this->pdfdata, $offset, 4) ==
'true') {
338 $objtype =
'boolean';
341 }
elseif (substr($this->pdfdata, $offset, 5) ==
'false') {
343 $objtype =
'boolean';
346 }
elseif (substr($this->pdfdata, $offset, 6) ==
'stream') {
350 if (preg_match(
'/^[\r\n]+(.*)[\r\n]*endstream/isU', substr($this->pdfdata, $offset), $matches) == 1) {
351 $objval = $matches[1];
352 $offset += strlen($matches[0]);
354 }
elseif (substr($this->pdfdata, $offset, 9) ==
'endstream') {
356 $objtype =
'endstream';
358 }
elseif (preg_match(
'/^([0-9]+)[\s]+([0-9]+)[\s]+R/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) {
361 $offset += strlen($matches[0]);
362 $objval = intval($matches[1]).
'_'.intval($matches[2]);
363 }
elseif (preg_match(
'/^([0-9]+)[\s]+([0-9]+)[\s]+obj/iU', substr($this->pdfdata, $offset, 33), $matches) == 1) {
366 $objval = intval($matches[1]).
'_'.intval($matches[2]);
367 $offset += strlen ($matches[0]);
368 }
elseif (($numlen = strspn($this->pdfdata,
'+-.0123456789', $offset)) > 0) {
370 $objtype =
'numeric';
371 $objval = substr($this->pdfdata, $offset, $numlen);
377 return array($objtype, $objval, $offset);
390 $obj = explode(
'_', $obj_ref);
391 if (($obj ===
false) OR (count($obj) != 2)) {
392 $this->
Error(
'Invalid object reference: '.$obj);
395 $objref = $obj[0].
' '.$obj[1].
' obj';
396 if (strpos($this->pdfdata, $objref, $offset) != $offset) {
398 return array(
'null',
'null', $offset);
401 $offset += strlen($objref);
408 $offset = $element[2];
410 if ($decoding AND ($element[0] ==
'stream') AND (isset($objdata[(
$i - 1)][0])) AND ($objdata[(
$i - 1)][0] ==
'<<')) {
411 $element[3] = $this->
decodeStream($objdata[(
$i - 1)][1], substr($element[1], 1));
413 $objdata[
$i] = $element;
415 }
while ($element[0] !=
'endobj');
430 if ($obj[0] ==
'objref') {
432 if (isset($this->objects[$obj[1]])) {
434 return $this->objects[$obj[1]];
435 }
elseif (isset($this->xref[$obj[1]])) {
437 $this->objects[$obj[1]] = $this->
getIndirectObject($obj[1], $this->xref[$obj[1]],
false);
438 return $this->objects[$obj[1]];
454 $slength = strlen($stream);
456 foreach ($sdic as $k => $v) {
458 if (($v[1] ==
'Length') AND (isset($sdic[($k + 1)])) AND ($sdic[($k + 1)][0] ==
'numeric')) {
460 $declength = intval($sdic[($k + 1)][1]);
461 if ($declength < $slength) {
462 $stream = substr($stream, 0, $declength);
463 $slength = $declength;
465 }
elseif (($v[1] ==
'Filter') AND (isset($sdic[($k + 1)]))) {
468 if ($objval[0] ==
'/') {
470 $filters[] = $objval[1];
471 }
elseif ($objval[0] ==
'[') {
473 foreach ($objval[1] as $flt) {
474 if ($flt[0] ==
'/') {
475 $filters[] = $flt[1];
483 $remaining_filters = array();
484 foreach ($filters as $filter) {
485 if (in_array($filter, $this->FilterDecoders->getAvailableFilters())) {
486 $stream = $this->FilterDecoders->decodeFilter($filter, $stream);
489 $remaining_filters[] = $filter;
492 return array($stream, $remaining_filters);
503 die(
'<strong>TCPDF_PARSER ERROR: </strong>'.$msg);
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
getXrefData($offset=0, $xref=array())
Get xref (cross-reference table) and trailer data from PDF document data.
This is a PHP class for parsing PDF documents.
getParsedData()
Return an array of parsed PDF document objects.
This is a PHP class for decoding common PDF filters (PDF 32000-2008 - 7.4 Filters).
decodeStream($sdic, $stream)
Decode the specified stream.
getRawObject($offset=0)
Get object type, raw value and offset to next object.
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
__construct($data)
Parse a PDF document an return an array of objects.
Error($msg)
This method is automatically called in case of fatal error; it simply outputs the message and halts t...
getIndirectObject($obj_ref, $offset=0, $decoding=true)
Get content of indirect object.
$objects
Array of PDF objects.
getObjectVal($obj)
Get the content of object, resolving indect object reference if necessary.