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

Add TcPdfOutput #53

Merged
merged 18 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/example/qr.png
/example/qr.svg
/.php_cs.cache
/example/TcPdfOutput/tcpdf_example.pdf
/example/HtmlOutput/html-example.htm
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"phpunit/phpunit": "^6.4|^7.0",
"symfony/css-selector": "^4.2",
"phpstan/phpstan": "^0.12.23",
"friendsofphp/php-cs-fixer": "^2.16"
"friendsofphp/php-cs-fixer": "^2.16",
"tecnickcom/tcpdf": "^6.3"
},
"suggest": {
"tecnickcom/tcpdf": "Needed to create pdfs with TcPdfOutput"
},
"autoload": {
"psr-4": {
Expand Down
76 changes: 69 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions example/HtmlOutput/html-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Sprain\SwissQrBill as QrBill;

require __DIR__ . '/../../vendor/autoload.php';

// 1. Let's load the base example to define the qr bill contents
require __DIR__ . '/../example.php';

// 2. Create a full payment part in HTML
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');

$html = $output
->setPrintable(false)
->setQrCodeImageFormat(QrBill\QrCode\QrCode::FILE_FORMAT_SVG)
->getPaymentPart();

// 3. For demo purposes, let's save the generated example in a file
$examplePath = __DIR__ . '/html-example.htm';
file_put_contents($examplePath, $html);

print 'HTML example created here: ' . $examplePath;
26 changes: 26 additions & 0 deletions example/TcPdfOutput/tcpdf-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Sprain\SwissQrBill as QrBill;

require __DIR__ . '/../../vendor/autoload.php';

// 1. Let's load the base example to define the qr bill contents
require __DIR__ . '/../example.php';

// 2. Create a TCPDF instance (or use an existing one from your project)
$tcPdf = new TCPDF('P', 'mm', 'A4', true, 'ISO-8859-1');
$tcPdf->setPrintHeader(false);
$tcPdf->setPrintFooter(false);
$tcPdf->AddPage();

// 3. Create a full payment part for TcPDF
$output = new QrBill\PaymentPart\Output\TcPdfOutput\TcPdfOutput($qrBill, 'en', $tcPdf);
$output
->setPrintable(true)
->getPaymentPart();

// 4. For demo purposes, let's save the generated example in a file
$examplePath = __DIR__ . "/tcpdf_example.pdf";
$tcPdf->Output($examplePath, 'F');

print "PDF example created here : ".$examplePath;
29 changes: 17 additions & 12 deletions example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

require __DIR__ . '/../vendor/autoload.php';

// This example shows how to create a classic qr bill.

// Create a new instance of QrBill, containing default headers with fixed values
$qrBill = QrBill\QrBill::create();

Expand All @@ -19,7 +21,7 @@

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH4431999123000889012' // Note that this is a special QR-IBAN which are currently not yet available in real life (as of June 2019)
'CH4431999123000889012' // This is a special QR-IBAN. Classic IBANs will not be valid here.
));

// Add debtor information
Expand Down Expand Up @@ -49,7 +51,7 @@
// This is what you will need to identify incoming payments.
$referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate(
'210000', // you receive this number from your bank
'313947143000901' // a number to match the payment with your other data, e.g. an invoice number
'313947143000901' // a number to match the payment with your internal data, e.g. an invoice number
);

$qrBill->setPaymentReference(
Expand All @@ -58,9 +60,15 @@
$referenceNumber
));

// Time to output something!
//
// Get the QR code image …
// Optionally, add some human-readable information about what the bill is for.
// This information is only for the person who will pay the invoice.
$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');
Expand All @@ -71,10 +79,7 @@
exit;
}

// … or output a full payment part
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');

print $output
->setPrintable(false)
->setQrCodeImageFormat(QrBill\QrCode\QrCode::FILE_FORMAT_SVG)
->getPaymentPart();
// Next: Output full payment parts, depending on the format you want to use:
//
// - HtmlOutput/html-example.php
// - TcPdfOutput/tcpdf-example.php
14 changes: 4 additions & 10 deletions example/example_scor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

require __DIR__ . '/../vendor/autoload.php';

// This is an example of how to create a qr bill with a reference in SCOR format.

// Create a new instance of QrBill, containing default headers with fixed values
$qrBill = QrBill\QrBill::create();

Expand All @@ -19,7 +21,7 @@

$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH9300762011623852957'
'CH9300762011623852957' // With SCOR, this is a classic iban. QR-IBANs will not be valid here.
));

// Add debtor information
Expand Down Expand Up @@ -64,12 +66,4 @@
print $violation->getMessage()."\n";
}
exit;
}

// … or output a full payment part
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');

print $output
->setPrintable(false)
->setQrCodeImageFormat(QrBill\QrCode\QrCode::FILE_FORMAT_SVG)
->getPaymentPart();
}
Loading