{"id":16467153,"url":"https://github.com/horstoeko/zugferdvisualizer","last_synced_at":"2025-10-04T04:58:45.518Z","repository":{"id":195129040,"uuid":"692311526","full_name":"horstoeko/zugferdvisualizer","owner":"horstoeko","description":"Visualizer for ZUGFeRD/XRechnung/Factur-X","archived":false,"fork":false,"pushed_at":"2025-09-08T15:39:50.000Z","size":194,"stargazers_count":32,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-01T09:51:35.728Z","etag":null,"topics":["electronic-invoices","electronic-invoicing","en16931","factur-x","php","php7","php8","vizualisation","xrechnung","xrechnung-visualization","zugferd"],"latest_commit_sha":null,"homepage":"https://github.com/horstoeko/zugferdvisualizer","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/horstoeko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-16T05:04:21.000Z","updated_at":"2025-09-08T15:39:48.000Z","dependencies_parsed_at":"2024-01-08T05:36:46.761Z","dependency_job_id":"74adc3c4-c514-4f2f-a1ba-6f2894bd0f7e","html_url":"https://github.com/horstoeko/zugferdvisualizer","commit_stats":{"total_commits":72,"total_committers":3,"mean_commits":24.0,"dds":"0.13888888888888884","last_synced_commit":"b56720bfa3b54989c2fcaada405a9b45560915ac"},"previous_names":["horstoeko/zugferdvisualizer"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/horstoeko/zugferdvisualizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/horstoeko%2Fzugferdvisualizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/horstoeko%2Fzugferdvisualizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/horstoeko%2Fzugferdvisualizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/horstoeko%2Fzugferdvisualizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/horstoeko","download_url":"https://codeload.github.com/horstoeko/zugferdvisualizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/horstoeko%2Fzugferdvisualizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278266894,"owners_count":25958733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electronic-invoices","electronic-invoicing","en16931","factur-x","php","php7","php8","vizualisation","xrechnung","xrechnung-visualization","zugferd"],"created_at":"2024-10-11T11:46:17.652Z","updated_at":"2025-10-04T04:58:45.503Z","avatar_url":"https://github.com/horstoeko.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZUGFeRD/XRechnung/Factur-X Visualizer\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/horstoeko/zugferdvisualizer.svg?style=plastic)](https://packagist.org/packages/horstoeko/zugferdvisualizer)\n[![PHP version](https://img.shields.io/packagist/php-v/horstoeko/zugferdvisualizer.svg?style=plastic)](https://packagist.org/packages/horstoeko/zugferdvisualizer)\n[![License](https://img.shields.io/packagist/l/horstoeko/zugferdvisualizer.svg?style=plastic)](https://packagist.org/packages/horstoeko/zugferdvisualizer)\n\n[![Build Status](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.ci.yml/badge.svg)](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.ci.yml)\n[![Release Status](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.release.yml/badge.svg)](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.release.yml)\n\n## Table of Contents\n\n- [ZUGFeRD/XRechnung/Factur-X Visualizer](#zugferdxrechnungfactur-x-visualizer)\n  - [Table of Contents](#table-of-contents)\n  - [License](#license)\n  - [Overview](#overview)\n  - [Dependencies](#dependencies)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Create HTML markup from existing invoice document (XML) using built-in template](#create-html-markup-from-existing-invoice-document-xml-using-built-in-template)\n    - [Create a PDF file from existing invoice document (XML) using built-in template](#create-a-pdf-file-from-existing-invoice-document-xml-using-built-in-template)\n    - [Create a PDF string from existing invoice document (XML) using built-in template](#create-a-pdf-string-from-existing-invoice-document-xml-using-built-in-template)\n    - [Create a PDF string from document builder and merge XML with generated PDF](#create-a-pdf-string-from-document-builder-and-merge-xml-with-generated-pdf)\n    - [Create a custom renderer](#create-a-custom-renderer)\n    - [Use a custom renderer](#use-a-custom-renderer)\n    - [Use the built-in Laravel renderer](#use-the-built-in-laravel-renderer)\n    - [Set PDF-Options](#set-pdf-options)\n      - [Set options before instanciating the internal PDF-Engine (```setPdfPreInitCallback```)](#set-options-before-instanciating-the-internal-pdf-engine-setpdfpreinitcallback)\n      - [Set options after instanciating the internal PDF-Engine (```setPdfRuntimeInitCallback```)](#set-options-after-instanciating-the-internal-pdf-engine-setpdfruntimeinitcallback)\n      - [Working with custom fonts](#working-with-custom-fonts)\n\n## License\n\nThe code in this project is provided under the [MIT](https://opensource.org/licenses/MIT) license.\n\n## Overview\n\nWith `horstoeko/zugferdvisualizer` you can visualize ZUGFeRD/XRechnung/Factur-X documents. This package is an addon for [horstoeko/zugferd](https://github.com/horstoeko/zugferd) package. The system uses a markup template (HTML) to render the output. On top you can create a PDF from the rendered markup\n\n## Dependencies\n\nThis package makes use of\n\n- [horstoeko/zugferd](https://github.com/horstoeko/zugferd)\n- [mPdf](https://github.com/mpdf/mpdf)\n\n## Installation\n\nThere is one recommended way to install `horstoeko/zugferdvisualizer` via [Composer](https://getcomposer.org/):\n\n* adding the dependency to your ``composer.json`` file:\n\n```js\n  \"require\": {\n      ..\n      \"horstoeko/zugferdvisualizer\":\"^1\",\n      ..\n  },\n```\n\n## Usage\n\n### Create HTML markup from existing invoice document (XML) using built-in template\n\n```php\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\n\nrequire dirname(__FILE__) . \"/../vendor/autoload.php\";\n\n$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . \"/invoice_1.xml\");\n\n$visualizer = new ZugferdVisualizer($document);\n$visualizer-\u003esetDefaultTemplate();\n\necho $visualizer-\u003erenderMarkup();\n```\n\n### Create a PDF file from existing invoice document (XML) using built-in template\n\nFind there [full example here](https://github.com/horstoeko/zugferdvisualizer/blob/master/examples/BuildFromDocumentReader.php)\n\n```php\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\n\nrequire dirname(__FILE__) . \"/../vendor/autoload.php\";\n\n$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . \"/invoice_1.xml\");\n\n$visualizer = new ZugferdVisualizer($document);\n$visualizer-\u003esetDefaultTemplate();\n$visualizer-\u003esetPdfFontDefault(\"courier\");\n$visualizer-\u003erenderPdfFile(dirname(__FILE__) . \"/invoice_1.pdf\");\n```\n\n### Create a PDF string from existing invoice document (XML) using built-in template\n\n```php\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\n\nrequire dirname(__FILE__) . \"/../vendor/autoload.php\";\n\n$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . \"/invoice_1.xml\");\n\n$visualizer = new ZugferdVisualizer($document);\n$visualizer-\u003esetDefaultTemplate();\n$visualizer-\u003esetPdfFontDefault(\"courier\");\n\n$pdfString = $visualizer-\u003erenderPdf();\n```\n\n### Create a PDF string from document builder and merge XML with generated PDF\n\nFind there [full example here](https://github.com/horstoeko/zugferdvisualizer/blob/master/examples/BuildFromDocumentBuilder.php)\n\n```php\n$document = ZugferdDocumentBuilder::CreateNew(ZugferdProfiles::PROFILE_EN16931);\n$document\n    -\u003esetDocumentInformation(\"471102\", \"380\", \\DateTime::createFromFormat(\"Ymd\", \"20180305\"), \"EUR\")\n    -\u003e...\n\n$reader = ZugferdDocumentReader::readAndGuessFromContent($document-\u003egetContent());\n\n$visualizer = new ZugferdVisualizer($reader);\n$visualizer-\u003esetDefaultTemplate();\n$visualizer-\u003esetPdfFontDefault(\"courier\");\n$visualizer-\u003esetPdfPaperSize('A4-P');\n\n$merger = new ZugferdDocumentPdfMerger($document-\u003egetContent(), $visualizer-\u003erenderPdf());\n$merger-\u003egenerateDocument();\n$merger-\u003esaveDocument(dirname(__FILE__) . \"/invoice_2.pdf\");\n```\n\n### Create a custom renderer\n\nIf you want to implement your own markup renderer, then your class must implement the interface `ZugferdVisualizerMarkupRendererContract`. The interface defines two methods:\n\n* `templateExists`\n* `render`\n\n```php\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\contracts\\ZugferdVisualizerMarkupRendererContract;\n\nclass MyOwnRenderer implements ZugferdVisualizerMarkupRendererContract\n{\n    public function templateExists(string $template): bool\n    {\n        // Put your logic here\n        // Method must return a boolean value\n    }\n\n    public function render(ZugferdDocumentReader $document, string $template): string\n    {\n        // Put your logic here\n        // Method must return a string (rendered HTML markup)\n    }\n}\n```\n\n### Use a custom renderer\n\n```php\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\n\nrequire dirname(__FILE__) . \"/../vendor/autoload.php\";\n\n$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . \"/invoice_1.xml\");\n\n$visualizer = new ZugferdVisualizer($document);\n$visualizer-\u003esetRenderer(new MyOwnRenderer());\n$visualizer-\u003esetTemplate('/assets/myowntemplate.tmpl');\n\necho $visualizer-\u003erenderMarkup();\n```\n\n### Use the built-in Laravel renderer\n\nThe ```ZugferdVisualizerLaravelRenderer``` can be used within the Laravel-Framework:\n\n```php\nnamespace App\\Http\\Controllers;\n\nuse Illuminate\\Http\\Request;\nuse horstoeko\\zugferd\\ZugferdDocumentReader;\nuse horstoeko\\zugferdvisualizer\\renderer\\ZugferdVisualizerLaravelRenderer;\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\n\nclass ZugferdController extends Controller\n{\n    public function index(Request $request)\n    {\n        $document = ZugferdDocumentReader::readAndGuessFromFile(storage_path('app/invoice_1.xml'));\n\n        $visualizer = new ZugferdVisualizer($document);\n        $visualizer-\u003esetRenderer(app(ZugferdVisualizerLaravelRenderer::class));\n        $visualizer-\u003esetTemplate('zugferd'); // ~/resources/views/zugferd.blade.php\n\n        return $visualizer-\u003erenderMarkup();\n    }\n\n    public function download(Request $request)\n    {\n        $document = ZugferdDocumentReader::readAndGuessFromFile(storage_path('app/invoice_1.xml'));\n\n        $visualizer = new ZugferdVisualizer($document);\n        $visualizer-\u003esetRenderer(app(ZugferdVisualizerLaravelRenderer::class));\n        $visualizer-\u003esetTemplate('zugferd');\n        $visualizer-\u003esetPdfFontDefault(\"courier\");\n        $visualizer-\u003esetPdfPaperSize('A4-P');\n        $visualizer-\u003erenderPdfFile(storage_path('app/invoice_1.pdf'));\n\n        $headers = [\n            'Content-Type: application/pdf',\n        ];\n\n        return response()-\u003edownload(storage_path('app/invoice_1.pdf'), \"invoice_1.pdf\", $headers);\n    }\n}\n```\n\n### Set PDF-Options\n\nIf you want to make further settings to the internal PDF engine, then you can change further settings using a callback.\nThe usage is as follows:\n\n#### Set options before instanciating the internal PDF-Engine (```setPdfPreInitCallback```)\n\n```php\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\nuse Mpdf\\Mpdf;\n\n$visualizer = new ZugferdVisualizer(static::$document);\n$visualizer-\u003esetDefaultTemplate();\n$visualizer-\u003esetPdfPreInitCallback(function (array $config, ZugferdVisualizer $visualizer) {\n    $config[\"orientation\"] = \"L\";\n    return $config;\n});\n```\n\n#### Set options after instanciating the internal PDF-Engine (```setPdfRuntimeInitCallback```)\n\n```php\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\nuse Mpdf\\Mpdf;\n\n$visualizer = new ZugferdVisualizer(static::$document);\n$visualizer-\u003esetDefaultTemplate();\n$visualizer-\u003esetPdfRuntimeInitCallback(function (Mpdf $mpdf, ZugferdVisualizer $visualizer) {\n    $mpdf-\u003epdf_version = \"1.7\";\n});\n```\n\n#### Working with custom fonts\n\nIf you would like to use your own fonts, that's no problem at all. First you have to specify one or more directories in which your fonts are located:\n\n```php\nuse horstoeko\\zugferdvisualizer\\ZugferdVisualizer;\nuse Mpdf\\Mpdf;\n\n$visualizer = new ZugferdVisualizer(static::$document);\n$visualizer-\u003eaddPdfFontDirectory('/var/fonts1/');\n$visualizer-\u003eaddPdfFontDirectory('/var/fonts2/');\n```\n\nNext, you need to define the font properties:\n\n* The first parameter sets the name of the font-family\n* Thé second parameter sets the type of the font\n  * R - Regular\n  * I - Italic\n  * B - Bold\n  * BI - Bold \u0026 Italic\n* The third parameter sets the filename under which the font can be found in the specified font-directories\n\n```php\n$visualizer-\u003eaddPdfFontData('comicsans', 'R', 'comic.ttf');\n$visualizer-\u003eaddPdfFontData('comicsans', 'I', 'comici.ttf');\n```\n\nIf you want to set a custom font as the default font, you can use the following method:\n\n```php\n$visualizer-\u003esetPdfFontDefault(\"comicsans\");\n```\n\nYou can also use the name of the font family in the style attribute of any HTML elements in your template:\n\n```html\n\u003cp style=\"font-family: comicsans\"\u003eText in Comic Sans\u003c/p\u003e\n```\n\nFor more configuration options, please consult the documentation of [mPdf](https://mpdf.github.io/configuration/configuration-v7-x.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorstoeko%2Fzugferdvisualizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhorstoeko%2Fzugferdvisualizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorstoeko%2Fzugferdvisualizer/lists"}