Skip to content

Commit c7c8bf4

Browse files
authored
Merge pull request #1 from myokyawhtun/master
Actualize fork from source repository
2 parents e395658 + a0e6fca commit c7c8bf4

13 files changed

+107
-91
lines changed

PDFMerger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function addPDF($filepath, $pages = 'all')
6868
}
6969
else
7070
{
71-
throw new exception("Could not locate PDF on '$filepath'");
71+
throw new \exception("Could not locate PDF on '$filepath'");
7272
}
7373

7474
return $this;
@@ -84,7 +84,7 @@ public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
8484
{
8585
if(!isset($this->_files) || !is_array($this->_files)): throw new exception("No PDFs to merge."); endif;
8686

87-
$fpdi = new TCPDI;
87+
$fpdi = new \TCPDI;
8888
$fpdi->SetPrintHeader(false);
8989
$fpdi->SetPrintFooter(false);
9090

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#PDFMerger for PHP (PHP 5 and above up to PHP 7.1 Compatible)
1+
#PDFMerger for PHP (PHP 5 and above up to PHP 7.1 and PHP 8 Compatible)
22

33
PDFMerger created by Jarrod Nettles December 2009 jarrod@squarecrow.com
44

@@ -8,7 +8,7 @@ Updated by Vasiliy Zaytsev February 2016 vasiliy.zaytsev@ffwagency.com
88
- Uses patched tcpdi_parser 1.0 by Paul Nicholls with own TCPdiParserException
99
- Uses TCPDI 1.0 by Paul Nicholls with FPDF_TPL extension 1.2.3 by Setasign
1010

11-
## PHP 5 Compatible
11+
## PHP 5,6,7 and 8 Compatible
1212

1313
I have made some changes in original codes to make PHPMerger compatible for PHP 5.
1414

@@ -20,6 +20,20 @@ I tested with PHP 7.1 on my local machine and it still works.
2020

2121
FPDF and FPDI libraries replaced by TCPDF with TCPDI extension and parser.
2222

23+
### Using Namespace
24+
25+
```php
26+
require_once ('PDFMerger/PDFMerger.php');
27+
28+
use PDFMerger\PDFMerger;
29+
$pdf = new PDFMerger;
30+
31+
$pdf->addPDF('a.pdf');
32+
$pdf->addPDF('b.pdf');
33+
34+
$pdf->merge('download','merged.pdf');
35+
```
36+
2337
### Example Usage
2438
```php
2539
include 'PDFMerger.php';
@@ -36,4 +50,4 @@ $pdf->merge('file', 'samplepdfs/TEST2.pdf'); // generate the file
3650
$pdf->merge('download', 'samplepdfs/test.pdf'); // force download
3751

3852
// REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
39-
```
53+
```

tcpdf/include/barcodes/datamatrix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ protected function lookAheadTest($data, $pos, $mode) {
629629
if ($numch[ENC_C40] == $numch[ENC_X12]) {
630630
$k = ($pos + $charscount + 1);
631631
while ($k < $data_length) {
632-
$tmpchr = ord($data{$k});
632+
$tmpchr = ord($data[$k]);
633633
if ($this->isCharMode($tmpchr, ENC_X12)) {
634634
return ENC_X12;
635635
} elseif (!($this->isCharMode($tmpchr, ENC_X12) OR $this->isCharMode($tmpchr, ENC_C40))) {

tcpdf/include/barcodes/pdf417.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ protected function getCompaction($mode, $code, $addmode=true) {
878878
$txtarr = array(); // array of characters and sub-mode switching characters
879879
$codelen = strlen($code);
880880
for ($i = 0; $i < $codelen; ++$i) {
881-
$chval = ord($code{$i});
881+
$chval = ord($code[$i]);
882882
if (($k = array_search($chval, $this->textsubmodes[$submode])) !== false) {
883883
// we are on the same sub-mode
884884
$txtarr[] = $k;
@@ -888,7 +888,7 @@ protected function getCompaction($mode, $code, $addmode=true) {
888888
// search new sub-mode
889889
if (($s != $submode) AND (($k = array_search($chval, $this->textsubmodes[$s])) !== false)) {
890890
// $s is the new submode
891-
if (((($i + 1) == $codelen) OR ((($i + 1) < $codelen) AND (array_search(ord($code{($i + 1)}), $this->textsubmodes[$submode]) !== false))) AND (($s == 3) OR (($s == 0) AND ($submode == 1)))) {
891+
if (((($i + 1) == $codelen) OR ((($i + 1) < $codelen) AND (array_search(ord($code[($i + 1)]), $this->textsubmodes[$submode]) !== false))) AND (($s == 3) OR (($s == 0) AND ($submode == 1)))) {
892892
// shift (temporary change only for this char)
893893
if ($s == 3) {
894894
// shift to puntuaction
@@ -952,7 +952,7 @@ protected function getCompaction($mode, $code, $addmode=true) {
952952
$cw = array_merge($cw, $cw6);
953953
} else {
954954
for ($i = 0; $i < $sublen; ++$i) {
955-
$cw[] = ord($code{$i});
955+
$cw[] = ord($code[$i]);
956956
}
957957
}
958958
$code = $rest;

tcpdf/include/tcpdf_filters.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public static function decodeFilterLZWDecode($data) {
279279
// convert string to binary string
280280
$bitstring = '';
281281
for ($i = 0; $i < $data_length; ++$i) {
282-
$bitstring .= sprintf('%08b', ord($data{$i}));
282+
$bitstring .= sprintf('%08b', ord($data[$i]));
283283
}
284284
// get the number of bits
285285
$data_length = strlen($bitstring);
@@ -376,7 +376,7 @@ public static function decodeFilterRunLengthDecode($data) {
376376
$i = 0;
377377
while($i < $data_length) {
378378
// get current byte value
379-
$byte = ord($data{$i});
379+
$byte = ord($data[$i]);
380380
if ($byte == 128) {
381381
// a length value of 128 denote EOD
382382
break;
@@ -389,7 +389,7 @@ public static function decodeFilterRunLengthDecode($data) {
389389
} else {
390390
// if length is in the range 129 to 255,
391391
// the following single byte shall be copied 257 - length (2 to 128) times during decompression
392-
$decoded .= str_repeat($data{($i + 1)}, (257 - $byte));
392+
$decoded .= str_repeat($data[($i + 1)], (257 - $byte));
393393
// move to next block
394394
$i += 2;
395395
}

tcpdf/include/tcpdf_fonts.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,9 @@ public static function getFontRefSize($size, $refsize=12) {
16641664
* @public static
16651665
*/
16661666
public static function unichr($c, $unicode=true) {
1667-
if (!$unicode) {
1667+
if (is_null($c) || !strlen($c)) {
1668+
return '';
1669+
} elseif (!$unicode) {
16681670
return chr($c);
16691671
} elseif ($c <= 0x7F) {
16701672
// one byte

tcpdf/include/tcpdf_images.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static function _parsepng($file) {
315315
if ($n > 0) {
316316
$trns = array();
317317
for ($i = 0; $i < $n; ++ $i) {
318-
$trns[] = ord($t{$i});
318+
$trns[] = ord($t[$i]);
319319
}
320320
}
321321
}

tcpdf/include/tcpdf_static.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ public static function extractCSSproperties($cssdata) {
11361136
* @see setHtmlVSpace()
11371137
* @public static
11381138
*/
1139-
public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
1139+
public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) {
11401140
// configure parameters for HTML Tidy
11411141
if ($tidy_options === '') {
11421142
$tidy_options = array (
@@ -2475,7 +2475,7 @@ public static function getPageSizeFromFormat($format) {
24752475
* @since 5.0.010 (2010-05-17)
24762476
* @public static
24772477
*/
2478-
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
2478+
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) {
24792479
if (!isset($pagedim[$page])) {
24802480
// initialize array
24812481
$pagedim[$page] = array();

tcpdf/tcpdf.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12576,7 +12576,7 @@ protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
1257612576
$k = $this->k;
1257712577
$this->javascript .= sprintf("f".$name."=this.addField('%s','%s',%u,[%F,%F,%F,%F]);", $name, $type, $this->PageNo()-1, $x*$k, ($this->h-$y)*$k+1, ($x+$w)*$k, ($this->h-$y-$h)*$k+1)."\n";
1257812578
$this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
12579-
while (list($key, $val) = each($prop)) {
12579+
foreach ($prop as $key => $val) {
1258012580
if (strcmp(substr($key, -5), 'Color') == 0) {
1258112581
$val = TCPDF_COLORS::_JScolor($val);
1258212582
} else {
@@ -16539,7 +16539,7 @@ protected function getHtmlDomArray($html) {
1653916539
// get attributes
1654016540
preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
1654116541
$dom[$key]['attribute'] = array(); // reset attribute array
16542-
while (list($id, $name) = each($attr_array[1])) {
16542+
foreach ($attr_array[1] as $id => $name) {
1654316543
$dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
1654416544
}
1654516545
if (!empty($css)) {
@@ -16552,7 +16552,7 @@ protected function getHtmlDomArray($html) {
1655216552
// get style attributes
1655316553
preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
1655416554
$dom[$key]['style'] = array(); // reset style attribute array
16555-
while (list($id, $name) = each($style_array[1])) {
16555+
foreach ($style_array[1] as $id => $name) {
1655616556
// in case of duplicate attribute the last replace the previous
1655716557
$dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
1655816558
}
@@ -16890,10 +16890,10 @@ protected function getHtmlDomArray($html) {
1689016890
if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
1689116891
$dom[$key]['fontname'] = $this->default_monospaced_font;
1689216892
}
16893-
if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value']{1}) > 0) AND (intval($dom[$key]['value']{1}) < 7)) {
16893+
if (!empty($dom[$key]['value']) AND ($dom[$key]['value'][0] == 'h') AND (intval($dom[$key]['value'][1]) > 0) AND (intval($dom[$key]['value'][1]) < 7)) {
1689416894
// headings h1, h2, h3, h4, h5, h6
1689516895
if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
16896-
$headsize = (4 - intval($dom[$key]['value']{1})) * 2;
16896+
$headsize = (4 - intval($dom[$key]['value'][1])) * 2;
1689716897
$dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
1689816898
}
1689916899
if (!isset($dom[$key]['style']['font-weight'])) {
@@ -17775,7 +17775,7 @@ public function writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=fal
1777517775
// justify block
1777617776
if (!TCPDF_STATIC::empty_string($this->lispacer)) {
1777717777
$this->lispacer = '';
17778-
continue;
17778+
break;
1777917779
}
1778017780
preg_match('/([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]([0-9\.\+\-]*)[\s]('.$strpiece[1][0].')[\s](re)([\s]*)/x', $pmid, $xmatches);
1778117781
if (!isset($xmatches[1])) {

0 commit comments

Comments
 (0)