Skip to content

Commit c7c3e86

Browse files
committed
New functions to fetch page annotations
This functionality is used (and thus required) by corresponding new functions in TCPDI v1.1. This also bumps the version to 1.1, to match TCPDI.
1 parent 429a6e7 commit c7c3e86

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

tcpdi_parser.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22
//============================================================+
33
// File name : tcpdi_parser.php
4-
// Version : 1.0
4+
// Version : 1.1
55
// Begin : 2013-09-25
6-
// Last Update : 2013-09-25
6+
// Last Update : 2016-05-03
77
// Author : Paul Nicholls - https://github.com/pauln
88
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
99
//
@@ -44,7 +44,7 @@
4444
* This is a PHP class for parsing PDF documents.<br>
4545
* @author Paul Nicholls
4646
* @author Nicola Asuni
47-
* @version 1.0
47+
* @version 1.1
4848
*/
4949

5050
// include class for decoding filters
@@ -82,7 +82,7 @@
8282
* This is a PHP class for parsing PDF documents.<br>
8383
* Based on TCPDF_PARSER, part of the TCPDF project by Nicola Asuni.
8484
* @brief This is a PHP class for parsing PDF documents..
85-
* @version 1.0
85+
* @version 1.1
8686
* @author Paul Nicholls - github.com/pauln
8787
* @author Nicola Asuni - info@tecnick.com
8888
*/
@@ -1219,6 +1219,42 @@ private function _getPageResources ($obj) { // $obj = /Page
12191219
}
12201220
}
12211221

1222+
/**
1223+
* Get annotations from current page
1224+
*
1225+
* @return array
1226+
*/
1227+
public function getPageAnnotations() {
1228+
return $this->_getPageAnnotations($this->pages[$this->pageno]);
1229+
}
1230+
1231+
/**
1232+
* Get annotations from /Page
1233+
*
1234+
* @param array $obj Array of pdf-data
1235+
*/
1236+
private function _getPageAnnotations ($obj) { // $obj = /Page
1237+
$obj = $this->getObjectVal($obj);
1238+
1239+
// If the current object has an annotations
1240+
// dictionary associated with it, we use
1241+
// it. Otherwise, we move back to its
1242+
// parent object.
1243+
if (isset ($obj[1][1]['/Annots'])) {
1244+
$annots = $obj[1][1]['/Annots'];
1245+
} else {
1246+
if (!isset ($obj[1][1]['/Parent'])) {
1247+
return false;
1248+
} else {
1249+
$annots = $this->_getPageAnnotations($obj[1][1]['/Parent']);
1250+
}
1251+
}
1252+
1253+
if ($annots[0] == PDF_TYPE_OBJREF)
1254+
return $this->getObjectVal($annots);
1255+
return $annots;
1256+
}
1257+
12221258

12231259
/**
12241260
* Get content of current page

0 commit comments

Comments
 (0)