diff --git a/.travis.yml b/.travis.yml index 4528ce52..8cc85f20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ php: - 7.4 - 8.0 - 8.1 + - 8.2 before_script: - composer selfupdate diff --git a/CHANGELOG.md b/CHANGELOG.md index a172b5ac..9e0801b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [5.2.6](https://github.com/spipu/html2pdf/compare/v5.2.5...v5.2.6) - 2023-01-28 + + * add support of PHP 8.1 and PHP 8.2 + * remove useless files + ## [5.2.5](https://github.com/spipu/html2pdf/compare/v5.2.4...v5.2.5) - 2022-04-04 * fix security on scheme of css and image paths for windows paths diff --git a/README.md b/README.md index 9565cef8..7feaaa8b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Html2Pdf -Html2Pdf is a HTML to PDF converter written in PHP, and compatible with PHP **5.6** to **8.0**. +Html2Pdf is a HTML to PDF converter written in PHP, and compatible with PHP **5.6** to **8.2**. It allows the conversion of valid HTML in PDF format, to generate documents like invoices, documentation, ... diff --git a/src/Html2Pdf.php b/src/Html2Pdf.php index 6e05a18c..5d751663 100755 --- a/src/Html2Pdf.php +++ b/src/Html2Pdf.php @@ -75,6 +75,11 @@ class Html2Pdf protected $_encoding = ''; // charset encoding protected $_unicode = true; // means that the input text is unicode (default = true) + /** + * @var bool + */ + protected $_pdfa; + protected $_testTdInOnepage = true; // test of TD that can not take more than one page protected $_testIsImage = true; // test if the images exist or not protected $_fallbackImage = null; // fallback image to use in img tags @@ -242,7 +247,7 @@ public function getVersionAsArray() return array( 'major' => 5, 'minor' => 2, - 'revision' => 4 + 'revision' => 6 ); } @@ -1021,7 +1026,7 @@ protected function _setNewPositionForNewLine($curr = null) // if subPart => return because align left if ($this->_subPart || $this->_isSubPart || $this->_isForOneLine) { - $this->pdf->setWordSpacing(0); + $this->pdf->setWordSpacing(0.); return null; } @@ -1073,9 +1078,9 @@ protected function _setNewPositionForNewLine($curr = null) // if justify => set the word spacing if ($this->parsingCss->value['text-align'] === 'justify' && $e>1) { - $this->pdf->setWordSpacing(($wMax-$w)/($e-1)); + $this->pdf->setWordSpacing((float) ($wMax - $w) / (float) ($e - 1.)); } else { - $this->pdf->setWordSpacing(0); + $this->pdf->setWordSpacing(0.); } } diff --git a/src/MyPdf.php b/src/MyPdf.php index 384842d9..14d83c7e 100644 --- a/src/MyPdf.php +++ b/src/MyPdf.php @@ -13,8 +13,9 @@ namespace Spipu\Html2Pdf; use Spipu\Html2Pdf\Exception\HtmlParsingException; +use TCPDF; -class MyPdf extends \TCPDF +class MyPdf extends TCPDF { protected $_footerParam = array(); protected $_transf = array(); @@ -24,9 +25,14 @@ class MyPdf extends \TCPDF // used to make a radius with bezier : (4/3 * (sqrt(2) - 1)) const MY_ARC = 0.5522847498; - // nb of segment to build a arc with bezier curv + // nb of segment to build an arc with bezier curv const ARC_NB_SEGMENT = 8; + /** + * @var float + */ + protected $ws = 0.; + /** * class constructor * @@ -132,8 +138,8 @@ public function Footer() } /** - * after cloning a object, we does not want to clone all the front informations - * because it take a lot a time and a lot of memory => we use reference + * after cloning an object, we do not want to clone all the front information + * because it takes a lot a time and a lot of memory => we use reference * * @param myPdf &$pdf * @access public @@ -155,7 +161,7 @@ public function cloneFontFrom(&$pdf) * multiple public accessor for some private attributs * used only by cloneFontFrom * - * @return &array + * @return array * @access public */ public function &getFonts() @@ -198,7 +204,7 @@ public function &getN() /** * Verify that a Font is already loaded * - * @param string Font Key + * @param string $fontKey Font Key * @return boolean * @access public */ @@ -229,7 +235,7 @@ public function getWordSpacing() /** * set the Word Spacing * - * @param float word spacing + * @param float $ws word spacing * @access public */ public function setWordSpacing($ws = 0.) @@ -534,8 +540,8 @@ public function stopTransform() /** * add a Translate transformation * - * @param float $Tx - * @param float $Ty + * @param $xT + * @param $yT * @access public */ public function setTranslate($xT, $yT) @@ -556,8 +562,8 @@ public function setTranslate($xT, $yT) * add a Rotate transformation * * @param float $angle - * @param float $Cx - * @param float $Cy + * @param float|null $xC + * @param float|null $yC * @access public */ public function setRotation($angle, $xC = null, $yC = null) @@ -653,7 +659,6 @@ public function SetXY($x, $y, $rtloff = false) /** * multiple public accessor because Html2Pdf need to use TCPDF without being a extend of it * - * @param mixed * @return mixed * @access public */ @@ -1065,7 +1070,7 @@ protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false) * @param float $rx * @param float $ry * @param float $angleBegin in radians - * @param float $angleEng in radians + * @param float $angleEnd in radians * @param boolean $direction * @param boolean $drawFirst, true => add the first point * @param boolean $trans apply transformation @@ -1182,7 +1187,7 @@ protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s = // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line if ($v['D'] == 0 || $v['D']>4) { $this->_Line($x2, $y2, $trans); - return false; + return; } // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd @@ -1432,7 +1437,7 @@ public function createIndex( //Filling dots $w=$this->w-$this->lMargin-$this->rMargin-$pageCellSize-($level*8)-($strsize+2); - $nb=$w/$this->GetStringWidth('.'); + $nb = (int) ($w/$this->GetStringWidth('.')); $dots=str_repeat('.', $nb); $this->Cell($w, $this->FontSize+2, $dots, 0, 0, 'R'); @@ -1490,7 +1495,7 @@ public function getMyNumPage($page = null) * Start a new group of pages * * @access public - * @return integer; + * @return void * @see tcpdf::startPageGroup */ public function myStartPageGroup() diff --git a/src/Tests/Html2PdfTest.php b/src/Tests/Html2PdfTest.php index c965f309..6b566394 100644 --- a/src/Tests/Html2PdfTest.php +++ b/src/Tests/Html2PdfTest.php @@ -2,6 +2,8 @@ namespace Spipu\Html2Pdf\Tests; +use Spipu\Html2Pdf\Tag\AbstractTag; + /** * Class Html2PdfTest */ @@ -9,10 +11,7 @@ class Html2PdfTest extends AbstractTest { public function testExtensionTag() { - $tag = $this->createMock('Spipu\Html2Pdf\Tag\TagInterface'); - $tag->expects($this->any())->method('getName')->willReturn('test_tag'); - $tag->expects($this->exactly(4))->method('open'); - $tag->expects($this->exactly(2))->method('close'); + $tag = new testTag(); $extension = $this->createMock('Spipu\Html2Pdf\Extension\ExtensionInterface'); $extension->expects($this->any())->method('getName')->willReturn('test'); @@ -43,3 +42,19 @@ public function testSecurityKo() $object->writeHTML('
'); } } + +class testTag extends AbstractTag +{ + public function getName() + { + return 'test_tag'; + } + + public function open($properties) + { + } + + public function close($properties) + { + } +} diff --git a/test/generate.ps1 b/test/generate.ps1 deleted file mode 100644 index 40b0da2b..00000000 --- a/test/generate.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -# Windows PowerShell Script -$ErrorActionPreference = "Stop" - -# Go to current location -$CURRENT_FOLDER=(Get-Location) -Set-Location (Split-Path $MyInvocation.Line -Parent) - -# Remove the old generated PDF files -Remove-Item *.pdf - -# Go to the examples folder -Set-Location ../examples - -Get-ChildItem ./ -File | ForEach-Object { - $PHP_SCRIPT="$_" - $PDF_FILE="../test/$_" -replace ".php",".pdf" - Write-Output " - $PHP_SCRIPT > $PDF_FILE" - php $PHP_SCRIPT > $PDF_FILE -} - -# Go to the test folder to see the result -Set-Location ../test -Get-ChildItem - -# Restore the current location -Set-Location $CURRENT_FOLDER diff --git a/test/generate.sh b/test/generate.sh deleted file mode 100755 index 3b21b23c..00000000 --- a/test/generate.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -cd "$( dirname "${BASH_SOURCE[0]}" )" - -rm -f *.pdf - -cd ../examples -for PHP_SCRIPT in $(ls ./*.php); -do - PDF_FILE=`echo "$PHP_SCRIPT" | sed 's/\.php/\.pdf/g' | sed 's/\.\//\.\.\/test\//g'` - echo "Example $PHP_SCRIPT => $PDF_FILE" - php $PHP_SCRIPT > $PDF_FILE -done - -cd ../test -ls -l