Skip to content

Commit

Permalink
[ENH] Introducing ZugferdPdfValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Dec 28, 2024
1 parent 8115b1f commit d4c2b5b
Show file tree
Hide file tree
Showing 3 changed files with 1,159 additions and 7 deletions.
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
},
"require": {
"php": ">=7.3",
"jms/serializer": "^3",
"goetas-webservices/xsd2php-runtime": "^0.2.13",
"ext-simplexml": "*",
"symfony/validator": "^5|^6|^7",
"smalot/pdfparser": "^0|^2",
"goetas-webservices/xsd2php-runtime": "^0.2.13",
"horstoeko/mimedb": "^1",
"horstoeko/stringmanagement": "^1",
"jms/serializer": "^3",
"setasign/fpdf": "^1",
"setasign/fpdi": "^2",
"symfony/yaml": "^5|^6|^7",
"smalot/pdfparser": "^0|^2",
"symfony/finder": "^5.4",
"symfony/process": "^5|^6|^7",
"horstoeko/stringmanagement": "^1",
"horstoeko/mimedb": "^1"
"symfony/validator": "^5|^6|^7",
"symfony/yaml": "^5|^6|^7"
},
"require-dev": {
"goetas-webservices/xsd2php": "^0",
Expand Down
73 changes: 73 additions & 0 deletions examples/PdfValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

use horstoeko\zugferd\ZugferdPdfValidator;

require dirname(__FILE__) . "/../vendor/autoload.php";

/**
* Helper function for outputting the errors
*
* @param ZugferdPdfValidator $pdfValidator
* @return void
*/
function showValidationResult(ZugferdPdfValidator $pdfValidator): void
{
foreach ($pdfValidator->getProcessOutput() as $output) {
//echo $output . PHP_EOL;
}

if ($pdfValidator->hasProcessErrors()) {
echo "\033[01;31mProcess failed\e[0m\n";
foreach ($pdfValidator->getProcessErrors() as $processError) {
echo " - " . $processError . PHP_EOL;
}
} elseif ($pdfValidator->hasValidationErrors()) {
echo "\033[01;31mValidation failed\e[0m\n";
foreach ($pdfValidator->getValidationErrors() as $validationError) {
echo " - " . $validationError . PHP_EOL;
}
} else {
echo "\033[01;32mValidation passed\e[0m\n";
}
}


/* ----------------------------------------------------------------------------------
- Perform validation
---------------------------------------------------------------------------------- */

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/invoice_1.pdf"))->disableCleanup()->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/invoice_1.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_plain.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_0)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_plain.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_zf_en16931_1.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_zf_en16931_2.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_zf_en16931_3.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_zf_extended_1.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);

$pdfValidator = ZugferdPdfValidator::fromContent(file_get_contents(dirname(__FILE__) . "/../tests/assets/pdf_zf_xrechnung_1.pdf"))->disableCleanup()->setValidatorRuleset(ZugferdPdfValidator::RULESET_PDF_A_3B)->validate();

showValidationResult($pdfValidator);
Loading

0 comments on commit d4c2b5b

Please sign in to comment.