Skip to content

Support PhpWordOutput format #172

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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
af49888
Add composer phpunit.
sevjan May 17, 2022
003b983
Add php word output with first example for qr-full-set.docx
sevjan May 17, 2022
60383b5
Revert php word output test regenerate reference files not always true.
sevjan May 18, 2022
9f3a2dc
Replace svg string with QrCode file format constant.
sevjan May 18, 2022
a1dd61e
Replace svg string with QrCode file format constant. Fix invalid imag…
sevjan May 18, 2022
8642da5
Update phpword-example with file format png.
sevjan May 18, 2022
87b5e71
Exclude phpword and more cache files in gitignore.
sevjan May 18, 2022
8c5580a
Added consistent timestamp for the PhpWord test file.
sevjan May 19, 2022
ea9296b
Assert same for all files in the xyz.docx document.
sevjan May 19, 2022
0f71795
Improve readability for test data file directory path.
sevjan May 19, 2022
b0ac128
Add support for php word separator element when bill is not printable.
sevjan May 19, 2022
d6fb8da
Remove element type amount.
sevjan May 19, 2022
303a2a2
Add php word output with placeholders support.
sevjan May 19, 2022
b7ce288
Add TestData files for PhpWordOutput.
sevjan May 19, 2022
b9952ed
Add PhpWordHelper to convert from mmToTwip/Point. Replace measurements.
sevjan May 19, 2022
658c672
Add PhpWordHelper to convert from percent to pct.
sevjan May 19, 2022
4a404a0
Refactor widths and heights to a separate styel class.
sevjan May 19, 2022
3607195
Code style.
sevjan May 20, 2022
a578ed2
Revert "Add composer phpunit."
sevjan May 20, 2022
992aa26
Add phpoffice/phpword to composer.
sevjan May 20, 2022
d017fe2
Remove legacy use Output\Element\Amount.
sevjan May 20, 2022
88b653e
Resolve conflicts with another class in this namespace and code style.
sevjan May 20, 2022
76740e3
Remove unused parameter.
sevjan May 20, 2022
24e70e2
Round converted twips to match integers.
sevjan May 20, 2022
1813520
Update TestData php word output to match the changed mmToTwip convers…
sevjan May 20, 2022
b96a749
Type cast to int is needed.
sevjan May 20, 2022
0928a93
PhpWordOutput placeholder parameter isReceiptPart is not any longer n…
sevjan May 20, 2022
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/vendor
/example/qr.png
/example/qr.svg
/.php_cs.cache
/example/TcPdfOutput/tcpdf_example.pdf
/example/HtmlOutput/html-example.htm
/example/FpdfOutput/fpdf_example.pdf
/example/PhpWordOutput/phpword_example.docx
/.php_cs.cache
/.php-cs-fixer.cache
/.idea/
/.phpunit.result.cache
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"friendsofphp/php-cs-fixer": "^3.4",
"khanamiryan/qrcode-detector-decoder": "^1.0.3",
"phpstan/phpstan": "^1.2",
"tecnickcom/tcpdf": "^6.3.2"
"tecnickcom/tcpdf": "^6.3.2",
"phpoffice/phpword": "^0.18.3"
},
"suggest": {
"tecnickcom/tcpdf": "Needed to create pdfs with TcPdfOutput",
"fpdf/fpdf": "Needed to create pdfs with FpdfOutput"
"fpdf/fpdf": "Needed to create pdfs with FpdfOutput",
"phpoffice/phpword": "Needed to create doc/docx with PhpWordOutput"
},
"autoload": {
"psr-4": {
Expand Down
176 changes: 175 additions & 1 deletion composer.lock

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

35 changes: 35 additions & 0 deletions example/PhpWordOutput/phpword-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

ini_set('display_errors', 'on');

use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Converter;

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)
$phpword = new PhpWord();
$section = $phpword->addSection([
'paperSize' => 'A4',
'orientation' => 'portrait',
'marginTop' => Converter::cmToTwip(2.0),
'marginLeft' => Converter::cmToTwip(2.0),
'marginBottom' => Converter::cmToTwip(2.0),
'marginRight' => Converter::cmToTwip(2.0),
'headerHeight' => Converter::cmToTwip(2.0),
'footerHeight' => Converter::cmToTwip(2.0),
]);
// 3. Create a full payment part for TcPDF
/** @noinspection PhpUndefinedVariableInspection */
$output = new \Sprain\SwissQrBill\PaymentPart\Output\PhpWordOutput\PhpWordOutput($qrBill, 'en', $phpword);
$output
->setPrintable(false)
->setQrCodeImageFormat(\Sprain\SwissQrBill\QrCode\QrCode::FILE_FORMAT_PNG)
->getPaymentPart();
// 4. For demo purposes, let's save the generated example in a file
$examplePath = __DIR__."/phpword_example.docx";
$phpword->save($examplePath, download: true);

print "Word example created here : ".$examplePath;
7 changes: 7 additions & 0 deletions src/Exception/InvalidPhpWordImageFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

namespace Sprain\SwissQrBill\Exception;

final class InvalidPhpWordImageFormat extends \Exception
{
}
2 changes: 1 addition & 1 deletion src/PaymentPart/Output/FpdfOutput/FpdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getPaymentPart(): void

public function setQrCodeImageFormat(string $fileExtension): AbstractOutput
{
if ($fileExtension === 'svg') {
if ($fileExtension === QrCode::FILE_FORMAT_SVG) {
throw new InvalidFpdfImageFormat('SVG images are not allowed by FPDF.');
}

Expand Down
Loading