Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible method signatures #62

Open
garethellis36 opened this issue Oct 1, 2021 · 1 comment
Open

Incompatible method signatures #62

garethellis36 opened this issue Oct 1, 2021 · 1 comment

Comments

@garethellis36
Copy link

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.

@guianzollin
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants