Closed iloveratte closed 2 years ago
Exactly what php tells you, I'd assume: you do not provide the instance of Fpdf as third argument.
Did you follow this example exactly? https://github.com/sprain/php-swiss-qr-bill/blob/master/example/FpdfOutput/fpdf-example.php
Hi I used exactly the two files, just adjusted the path: my file to call it looks like this (drucken7.php):
`<?php declare(strict_types=1);
use Sprain\SwissQrBill as QrBill;
define('FPDF_FONTPATH','./../../../../vendor/setasign/fpdf/font/'); require('./../../../../vendor/setasign/fpdf/fpdf.php'); require './../../../../vendor/autoload.php';
// 1. Let's load the base example to define the qr bill contents require './example.php';
// 2. Create an FPDF instance (or use an existing one from your project) $fpdf = new \Fpdf\Fpdf('P', 'mm', 'A4'); $fpdf->AddPage();
// 3. Create a full payment part for FPDF $output = new QrBill\PaymentPart\Output\FpdfOutput\FpdfOutput($qrBill, 'en', $fpdf); $output ->setPrintable(false) ->getPaymentPart();
// 4. For demo purposes, let's save the generated example in a file $examplePath = "./fpdf_example.pdf"; $fpdf->Output($examplePath, 'F');
print "PDF example created here : " . $examplePath;`
the example included in it looks like this (example.php), also only the path has been adjusted.
`<?php declare(strict_types=1);
use Sprain\SwissQrBill as QrBill;
require './../../../../vendor/autoload.php';
// This is an example how to create a typical qr bill: // - with reference number // - with known debtor // - with specified amount // - with human-readable additional information // - using your QR-IBAN // // Likely the most common use-case in the business world.
// Create a new instance of QrBill, containing default headers with fixed values $qrBill = QrBill\QrBill::create();
// Add creditor information // Who will receive the payment and to which bank account? $qrBill->setCreditor( QrBill\DataGroup\Element\CombinedAddress::create( 'Robert Schneider AG', 'Rue du Lac 1268', '2501 Biel', 'CH' ));
$qrBill->setCreditorInformation( QrBill\DataGroup\Element\CreditorInformation::create( 'CH4431999123000889012' // This is a special QR-IBAN. Classic IBANs will not be valid here. ));
// Add debtor information // Who has to pay the invoice? This part is optional. // // Notice how you can use two different styles of addresses: CombinedAddress or StructuredAddress. // They are interchangeable for creditor as well as debtor. $qrBill->setUltimateDebtor( QrBill\DataGroup\Element\StructuredAddress::createWithStreet( 'Pia-Maria Rutschmann-Schnyder', 'Grosse Marktgasse', '28', '9400', 'Rorschach', 'CH' ));
// Add payment amount information // What amount is to be paid? $qrBill->setPaymentAmountInformation( QrBill\DataGroup\Element\PaymentAmountInformation::create( 'CHF', 2500.25 ));
// Add payment reference // This is what you will need to identify incoming payments. $referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate( '210000', // You receive this number from your bank (BESR-ID). Unless your bank is PostFinance, in that case use NULL. '313947143000901' // A number to match the payment with your internal data, e.g. an invoice number );
$qrBill->setPaymentReference( QrBill\DataGroup\Element\PaymentReference::create( QrBill\DataGroup\Element\PaymentReference::TYPE_QR, $referenceNumber ));
// Optionally, add some human-readable information about what the bill is for. $qrBill->setAdditionalInformation( QrBill\DataGroup\Element\AdditionalInformation::create( 'Invoice 123456, Gardening work' ) );
// Now get the QR code image and save it as a file. try { $qrBill->getQrCode()->writeFile(DIR . '/qr.png'); $qrBill->getQrCode()->writeFile(DIR . '/qr.svg'); } catch (Exception $e) { foreach($qrBill->getViolations() as $violation) { print $violation->getMessage()."\n"; } exit; }
// Next: Output full payment parts, depending on the format you want to use: // // - FpdfOutput/fpdf-example.php // - HtmlOutput/html-example.php // - TcPdfOutput/tcpdf-example.php`
nevertheless I get the following output:
Fatal error: Uncaught Error: Class "Fpdf\Fpdf" not found in /home/stephan/www/XYZ.ch/neu/admin/drucken7.php:13 Stack trace: #0 {main} thrown in /home/stephan/ www/XYZ.ch/neu/admin/drucken7.php on line 13
Your error now is Class "Fpdf\Fpdf" not found
, which means probably, that your ./../../../../vendor/setasign/fpdf/fpdf.php
-file does not contain the FPDF-class.
Also, why do you require fpdf.php
this separately? I think it should be a composer dependency and therefore work just fine if you let composer to the work.
btw, for multiline code view, you should use ```php
, for example:
```php
<your code>
<and another line>
Hello, what should I do now? I've been using fpdf for a long time, but I've copied all the files into one directory, I'm not happy with this "composer", I would have preferred to have copied all the files separately into a directory. because i only need these files for one application. but I definitely need FPDF.. That's why I'm asking for your help.
can I also use the latest FPDF without Composer? Also the Swiss QR Bill?
Finally, the Drucken7.php should be called up and the payment slip filled out with the customer data... Thanks for the help
can I also use the latest FPDF without Composer? Also the Swiss QR Bill?
To use this library you need to use the namespaced version of FPDF, available here. https://github.com/coreydoughty/Fpdf
If you want to go without using composer, it's doable, but out of the scope of where we provide support here.
I want to point out, for @iloveratte and everyone else finding this topic, that dependency management without composer in modern environments is nearly impossible. You would spent DAYS in trying to make dependencies work without composer. If you're a reasonable up-to-date programmer, learning to work with composer will not take you more than one day.
So even if composer seems complex to beginn with, within a year of development you will have saved weeks of work by using composer. And belive me, we all have been there: "Why do I have to learn composer". Well, after you did you will know.
Hi. So I can't get an example with FPDF or TCpdf to run.. only HTML.. but that's no use to me because I need a PDF. who can help me now? fpdf is preferred, but only the error appears: Uncaught TypeError: Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput::__construct(): Argument #3 ($fpdf) must be of type Fpdf\Fpdf, FPDF given``
Argument ($fpdf) must be of type Fpdf\Fpdf, FPDF given
You are using an fpdf instance named FPDF
.
The library expects the namespaced version of FPDF named Fpdf\Fpdf
.
composer require fpdf/fpdf
$fpdf = new Fpdf\Fpdf(…)
Hi, i use the Exemple, and i heave this Error..
Uncaught TypeError: Sprain\SwissQrBill\PaymentPart\Output\FpdfOutput\FpdfOutput::__construct(): Argument #3 ($fpdf) must be of type Fpdf\Fpdf, null given,
What its the Problem?