sprain / php-swiss-qr-bill

A PHP library to create Swiss QR bills | QR-Rechnung in PHP erstellen
MIT License
281 stars 82 forks source link

FpdfOutput mit bestehender Instanz #150

Closed nwwheeler closed 3 years ago

nwwheeler commented 3 years ago

Hallo Ich benutze FPDF in einem Script schon zum Erstellen eines Rechnungs-PDF mit Header und Footer was problemlos funktioniert:

class PDF extends FPDF {

function Header() { ...

In demselben Script möchte ich nun noch eine neues PDF mit dem QR-Bill erstellen:

$fpdf = new PDF(); $fpdf->AddPage();

$output = new QrBill\PaymentPart\Output\FpdfOutput\FpdfOutput($qrBill, 'de', $fpdf); $output ->setPrintable(false) ->getPaymentPart();

$Path = DIR . "/qr-bill.pdf"; $fpdf->Output($Path, 'F');

Bei diesem Versuch entsteht folgende Fehlermeldung:

Fatal error: Uncaught TypeError: Argument 3 passed to Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput::construct() must be an instance of Fpdf\Fpdf, instance of PDF given, called in ...... on line 730 and defined in ....../vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php:53 Stack trace: #0 ........(730): Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput->construct(Object(Sprain\SwissQrBill\QrBill), 'de', Object(PDF)) #1 {main} thrown in ........./vendor/sprain/swiss-qr-bill/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php on line 53

Wie kann ich meine bestehende Instanz von FPDF (PDF) nutzen für den Output ?

Besten Dank für jede Hilfe.

sprain commented 3 years ago

Wie kann ich meine bestehende Instanz von FPDF (PDF) nutzen für den Output ?

If your replace your original FPDF library with this namespaced version, then it should work.

DonatoDeluxe commented 2 years ago

Hello @sprain This fix sadly didn't work for me.

I'm also trying to output an extended class which doesn't work.

Fatal error: Uncaught TypeError: Argument 3 passed to Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput::__construct() must be an instance of Fpdf\Fpdf, instance of INVOICE given

Thank you for your help and time.

sprain commented 2 years ago

@DonatoDeluxe Please let us know what print get_class($yourFdpInstance); puts out for you. Then we can help, maybe.

sprain commented 2 years ago

@DonatoDeluxe Oh, I just realized you already provided the information: instance of INVOICE given. You must make sure you are injecting an FPDF instance. So it depends what your INVOICE is based on.

DonatoDeluxe commented 2 years ago

@sprain Thank you for your reply. My INVOICE class extends FPDF class.

sprain commented 2 years ago

My INVOICE class extends FPDF class.

If what you have is

class INVOICE extends Fpdf\Fpdf { /* … your class */ }

and then you do

$invoice = new INVOICE(); // or whatever way ist needed to get an instance of your invoice class
$output = new QrBill\PaymentPart\Output\FpdfOutput\FpdfOutput($qrBill, 'en', $invoice);

it should be working.

Otherwise we need to see some code to reproduce the problem in order to be of any further help here.

DonatoDeluxe commented 2 years ago

Hello @sprain

Yes in short the code was like that. I fixed it now with the "jurosh/pdf-merge" library where i create each PDF separately and then merge them together.

Thank you for your time and help.