libmergepdf
libmergepdf copied to clipboard
Incompatible method signatures
Declaration of setasign\Fpdi\FpdfTplTrait::AddPage($orientation = '', $size = '', $rotation = 0) should be compatible with TCPDF::AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
I want to use the commercial FPDI PDF parser from setasign. In order to do this, I have to use Fpdi2Driver
and pass in an instance of Fpdi
from setasign/fpdi
:
$merger = new Merger(new Fpdi2Driver(new Fpdi()));
Fpdi
extends FpdfTpl
(both from setasign/fpdi
)
FpdfTpl
extends \FPDF
This library provides an alias of \FPDF
which extends from TCPDF
(tecnickcom/tcpdf
).
Fpdi
and TCPDF
have incompatible method signatures on these methods:
Declaration of setasign\Fpdi\FpdfTplTrait::setPageFormat($size, $orientation) should be compatible with TCPDF::setPageFormat($format, $orientation = 'P')
Declaration of setasign\Fpdi\FpdfTplTrait::AddPage($orientation = '', $size = '', $rotation = 0) should be compatible with TCPDF::AddPage($orientation = '', $format = '', $keepmargins = false, $tocpage = false)
Declaration of setasign\Fpdi\FpdfTplTrait::Link($x, $y, $w, $h, $link) should be compatible with TCPDF::Link($x, $y, $w, $h, $link, $spaces = 0)
Declaration of setasign\Fpdi\FpdfTplTrait::SetDrawColor($r, $g = NULL, $b = NULL) should be compatible with TCPDF::SetDrawColor($col1 = 0, $col2 = -1, $col3 = -1, $col4 = -1, $ret = false, $name = '')
Probably others, I lost interest in manually fixing them just to get a different error message.
This generates a warning in PHP 7.4 and fatal errors in PHP 8.
Try something this:
composer.json
"iio/libmergepdf": "^4.0",
"tecnickcom/tcpdf": "6.3.*",
"setasign/fpdi": "^2.0"
Using Fpdi to sign a pdf
use setasign\Fpdi\Tcpdf\Fpdi;
...
$pdf = new Fpdi('P', 'mm', 'A4');
$pages = $pdf->setSourceFile('file.pdf');
$certificate = file_get_contents('certificate.crt');
for ($i = 1; $i <= $pages; $i++) {
$pdf->AddPage();
$page = $pdf->importPage($i);
$pdf->useTemplate($page, 0, 0);
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, array());
}
$pdf->Output($path, 'F');
Using libmergepdf to merge two pdfs
use iio\libmergepdf\Merger;
use iio\libmergepdf\Driver\TcpdiDriver;
...
$merger = new Merger(new TcpdiDriver);
$merger->addFile('file1.pdf');
$merger->addFile('file2.pdf');
$mergedPdf = $merger->merge();
return $mergedPdf;