Skip to content

Commit

Permalink
php-8 (#6)
Browse files Browse the repository at this point in the history
merged with latest changes on packagist
  • Loading branch information
lucajackal85 authored Jun 1, 2022
1 parent 7926553 commit 84beb3a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#PDFMerger for PHP (PHP 5 and above up to PHP 7.1 Compatible)
#PDFMerger for PHP (PHP 5 and above up to PHP 7.1 and PHP 8 Compatible)

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

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

## PHP 5 Compatible
## PHP 5,6,7 and 8 Compatible

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

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

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

### Using Namespace

```php
require_once ('PDFMerger/PDFMerger.php');

use PDFMerger\PDFMerger;
$pdf = new PDFMerger;

$pdf->addPDF('a.pdf');
$pdf->addPDF('b.pdf');

$pdf->merge('download','merged.pdf');
```

### Example Usage
```php
include 'PDFMerger.php';
Expand All @@ -36,4 +50,4 @@ $pdf->merge('file', 'samplepdfs/TEST2.pdf'); // generate the file
$pdf->merge('download', 'samplepdfs/test.pdf'); // force download

// REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
```
```
2 changes: 1 addition & 1 deletion tcpdf/include/barcodes/pdf417.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ protected function getCompaction($mode, $code, $addmode=true) {
// search new sub-mode
if (($s != $submode) AND (($k = array_search($chval, $this->textsubmodes[$s])) !== false)) {
// $s is the new submode
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)))) {
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)))) {
// shift (temporary change only for this char)
if ($s == 3) {
// shift to puntuaction
Expand Down
5 changes: 3 additions & 2 deletions tcpdf/include/tcpdf_fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1664,8 +1664,9 @@ public static function getFontRefSize($size, $refsize=12) {
* @public static
*/
public static function unichr($c, $unicode=true) {
$c = intval($c);
if (!$unicode) {
if (is_null($c) || !strlen($c)) {
return '';
} elseif (!$unicode) {
return chr($c);
} elseif ($c <= 0x7F) {
// one byte
Expand Down
4 changes: 2 additions & 2 deletions tcpdf/include/tcpdf_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public static function extractCSSproperties($cssdata) {
* @see setHtmlVSpace()
* @public static
*/
public static function fixHTMLCode($html, $default_css='', $tagvs='', $tidy_options='', &$tagvspaces) {
public static function fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces) {
// configure parameters for HTML Tidy
if ($tidy_options === '') {
$tidy_options = array (
Expand Down Expand Up @@ -2475,7 +2475,7 @@ public static function getPageSizeFromFormat($format) {
* @since 5.0.010 (2010-05-17)
* @public static
*/
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points=false, $k, $pagedim=array()) {
public static function setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()) {
if (!isset($pagedim[$page])) {
// initialize array
$pagedim[$page] = array();
Expand Down
10 changes: 5 additions & 5 deletions tcpdf/tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12576,7 +12576,7 @@ protected function _addfield($type, $name, $x, $y, $w, $h, $prop) {
$k = $this->k;
$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";
$this->javascript .= 'f'.$name.'.textSize='.$this->FontSizePt.";\n";
while (list($key, $val) = each($prop)) {
foreach ($prop as $key => $val) {
if (strcmp(substr($key, -5), 'Color') == 0) {
$val = TCPDF_COLORS::_JScolor($val);
} else {
Expand Down Expand Up @@ -16539,7 +16539,7 @@ protected function getHtmlDomArray($html) {
// get attributes
preg_match_all('/([^=\s]*)[\s]*=[\s]*"([^"]*)"/', $element, $attr_array, PREG_PATTERN_ORDER);
$dom[$key]['attribute'] = array(); // reset attribute array
while (list($id, $name) = each($attr_array[1])) {
foreach ($attr_array[1] as $id => $name) {
$dom[$key]['attribute'][strtolower($name)] = $attr_array[2][$id];
}
if (!empty($css)) {
Expand All @@ -16552,7 +16552,7 @@ protected function getHtmlDomArray($html) {
// get style attributes
preg_match_all('/([^;:\s]*):([^;]*)/', $dom[$key]['attribute']['style'], $style_array, PREG_PATTERN_ORDER);
$dom[$key]['style'] = array(); // reset style attribute array
while (list($id, $name) = each($style_array[1])) {
foreach ($style_array[1] as $id => $name) {
// in case of duplicate attribute the last replace the previous
$dom[$key]['style'][strtolower($name)] = trim($style_array[2][$id]);
}
Expand Down Expand Up @@ -16890,10 +16890,10 @@ protected function getHtmlDomArray($html) {
if (($dom[$key]['value'] == 'pre') OR ($dom[$key]['value'] == 'tt')) {
$dom[$key]['fontname'] = $this->default_monospaced_font;
}
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)) {
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)) {
// headings h1, h2, h3, h4, h5, h6
if (!isset($dom[$key]['attribute']['size']) AND !isset($dom[$key]['style']['font-size'])) {
$headsize = (4 - intval($dom[$key]['value']{1})) * 2;
$headsize = (4 - intval($dom[$key]['value'][1])) * 2;
$dom[$key]['fontsize'] = $dom[0]['fontsize'] + $headsize;
}
if (!isset($dom[$key]['style']['font-weight'])) {
Expand Down
4 changes: 2 additions & 2 deletions tcpdf/tcpdi_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ protected function getRawObject($offset=0, $data=null) {
}
case '<': // \x3C LESS-THAN SIGN
case '>': { // \x3E GREATER-THAN SIGN
if (isset($data{($offset + 1)}) AND ($data{($offset + 1)} == $char)) {
if (isset($data[($offset + 1)]) AND ($data[($offset + 1)] == $char)) {
// dictionary object
$objtype = PDF_TYPE_DICTIONARY;
if ($char == '<') {
Expand Down Expand Up @@ -1403,7 +1403,7 @@ private function _getPageRotation($obj) { // $obj = /Page
return false;
} else {
$res = $this->_getPageRotation($obj[1][1]['/Parent']);
if (is_array($res) && $res[0] == PDF_TYPE_OBJECT)
if ($res && $res[0] == PDF_TYPE_OBJECT)
return $res[1];
return $res;
}
Expand Down

0 comments on commit 84beb3a

Please sign in to comment.