PHPackages                             horstoeko/zugferdvisualizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. horstoeko/zugferdvisualizer

ActivePackage[Utility &amp; Helpers](/categories/utility)

horstoeko/zugferdvisualizer
===========================

A library

v1.0.10(1y ago)33198.3k↑32%52MITPHPPHP &gt;=7.3CI passing

Since Sep 17Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/horstoeko/zugferdvisualizer)[ Packagist](https://packagist.org/packages/horstoeko/zugferdvisualizer)[ Docs](https://github.com/horstoeko/zugferdvisualizer)[ RSS](/packages/horstoeko-zugferdvisualizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (14)Used By (2)

ZUGFeRD/XRechnung/Factur-X Visualizer
=====================================

[](#zugferdxrechnungfactur-x-visualizer)

[![Latest Stable Version](https://camo.githubusercontent.com/36d7b7e6f1ede9e555670215e771eadb3ed75d8430c52df989e6413a3c34bb0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686f7273746f656b6f2f7a75676665726476697375616c697a65722e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/horstoeko/zugferdvisualizer)[![PHP version](https://camo.githubusercontent.com/5fc85a124b441c54ac13c8b3b060fe05d80d180922b1714e4d14963635435fcc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f686f7273746f656b6f2f7a75676665726476697375616c697a65722e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/horstoeko/zugferdvisualizer)[![License](https://camo.githubusercontent.com/0fb611d41b77db43ed735d9e9e8d0a1ec87b162ef059824f3ad35db544c3dde1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f7273746f656b6f2f7a75676665726476697375616c697a65722e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/horstoeko/zugferdvisualizer)

[![Build Status](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.ci.yml/badge.svg)](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.ci.yml)[![Release Status](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.release.yml/badge.svg)](https://github.com/horstoeko/zugferdvisualizer/actions/workflows/build.release.yml)

Table of Contents
-----------------

[](#table-of-contents)

- [ZUGFeRD/XRechnung/Factur-X Visualizer](#zugferdxrechnungfactur-x-visualizer)
    - [Table of Contents](#table-of-contents)
    - [License](#license)
    - [Overview](#overview)
    - [Dependencies](#dependencies)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Create HTML markup from existing invoice document (XML) using built-in template](#create-html-markup-from-existing-invoice-document-xml-using-built-in-template)
        - [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)
        - [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)
        - [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)
        - [Create a custom renderer](#create-a-custom-renderer)
        - [Use a custom renderer](#use-a-custom-renderer)
        - [Use the built-in Laravel renderer](#use-the-built-in-laravel-renderer)
        - [Set PDF-Options](#set-pdf-options)
            - [Set options before instanciating the internal PDF-Engine (`setPdfPreInitCallback`)](#set-options-before-instanciating-the-internal-pdf-engine-setpdfpreinitcallback)
            - [Set options after instanciating the internal PDF-Engine (`setPdfRuntimeInitCallback`)](#set-options-after-instanciating-the-internal-pdf-engine-setpdfruntimeinitcallback)
            - [Working with custom fonts](#working-with-custom-fonts)

License
-------

[](#license)

The code in this project is provided under the [MIT](https://opensource.org/licenses/MIT) license.

Overview
--------

[](#overview)

With `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

Dependencies
------------

[](#dependencies)

This package makes use of

- [horstoeko/zugferd](https://github.com/horstoeko/zugferd)
- [mPdf](https://github.com/mpdf/mpdf)

Installation
------------

[](#installation)

There is one recommended way to install `horstoeko/zugferdvisualizer` via [Composer](https://getcomposer.org/):

- adding the dependency to your `composer.json` file:

```
  "require": {
      ..
      "horstoeko/zugferdvisualizer":"^1",
      ..
  },
```

Usage
-----

[](#usage)

### Create HTML markup from existing invoice document (XML) using built-in template

[](#create-html-markup-from-existing-invoice-document-xml-using-built-in-template)

```
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;

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

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/invoice_1.xml");

$visualizer = new ZugferdVisualizer($document);
$visualizer->setDefaultTemplate();

echo $visualizer->renderMarkup();
```

### 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)

Find there [full example here](https://github.com/horstoeko/zugferdvisualizer/blob/master/examples/BuildFromDocumentReader.php)

```
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;

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

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/invoice_1.xml");

$visualizer = new ZugferdVisualizer($document);
$visualizer->setDefaultTemplate();
$visualizer->setPdfFontDefault("courier");
$visualizer->renderPdfFile(dirname(__FILE__) . "/invoice_1.pdf");
```

### 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)

```
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;

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

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/invoice_1.xml");

$visualizer = new ZugferdVisualizer($document);
$visualizer->setDefaultTemplate();
$visualizer->setPdfFontDefault("courier");

$pdfString = $visualizer->renderPdf();
```

### 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)

Find there [full example here](https://github.com/horstoeko/zugferdvisualizer/blob/master/examples/BuildFromDocumentBuilder.php)

```
$document = ZugferdDocumentBuilder::CreateNew(ZugferdProfiles::PROFILE_EN16931);
$document
    ->setDocumentInformation("471102", "380", \DateTime::createFromFormat("Ymd", "20180305"), "EUR")
    ->...

$reader = ZugferdDocumentReader::readAndGuessFromContent($document->getContent());

$visualizer = new ZugferdVisualizer($reader);
$visualizer->setDefaultTemplate();
$visualizer->setPdfFontDefault("courier");
$visualizer->setPdfPaperSize('A4-P');

$merger = new ZugferdDocumentPdfMerger($document->getContent(), $visualizer->renderPdf());
$merger->generateDocument();
$merger->saveDocument(dirname(__FILE__) . "/invoice_2.pdf");
```

### Create a custom renderer

[](#create-a-custom-renderer)

If you want to implement your own markup renderer, then your class must implement the interface `ZugferdVisualizerMarkupRendererContract`. The interface defines two methods:

- `templateExists`
- `render`

```
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\contracts\ZugferdVisualizerMarkupRendererContract;

class MyOwnRenderer implements ZugferdVisualizerMarkupRendererContract
{
    public function templateExists(string $template): bool
    {
        // Put your logic here
        // Method must return a boolean value
    }

    public function render(ZugferdDocumentReader $document, string $template): string
    {
        // Put your logic here
        // Method must return a string (rendered HTML markup)
    }
}
```

### Use a custom renderer

[](#use-a-custom-renderer)

```
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;

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

$document = ZugferdDocumentReader::readAndGuessFromFile(dirname(__FILE__) . "/invoice_1.xml");

$visualizer = new ZugferdVisualizer($document);
$visualizer->setRenderer(new MyOwnRenderer());
$visualizer->setTemplate('/assets/myowntemplate.tmpl');

echo $visualizer->renderMarkup();
```

### Use the built-in Laravel renderer

[](#use-the-built-in-laravel-renderer)

The `ZugferdVisualizerLaravelRenderer` can be used within the Laravel-Framework:

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferdvisualizer\renderer\ZugferdVisualizerLaravelRenderer;
use horstoeko\zugferdvisualizer\ZugferdVisualizer;

class ZugferdController extends Controller
{
    public function index(Request $request)
    {
        $document = ZugferdDocumentReader::readAndGuessFromFile(storage_path('app/invoice_1.xml'));

        $visualizer = new ZugferdVisualizer($document);
        $visualizer->setRenderer(app(ZugferdVisualizerLaravelRenderer::class));
        $visualizer->setTemplate('zugferd'); // ~/resources/views/zugferd.blade.php

        return $visualizer->renderMarkup();
    }

    public function download(Request $request)
    {
        $document = ZugferdDocumentReader::readAndGuessFromFile(storage_path('app/invoice_1.xml'));

        $visualizer = new ZugferdVisualizer($document);
        $visualizer->setRenderer(app(ZugferdVisualizerLaravelRenderer::class));
        $visualizer->setTemplate('zugferd');
        $visualizer->setPdfFontDefault("courier");
        $visualizer->setPdfPaperSize('A4-P');
        $visualizer->renderPdfFile(storage_path('app/invoice_1.pdf'));

        $headers = [
            'Content-Type: application/pdf',
        ];

        return response()->download(storage_path('app/invoice_1.pdf'), "invoice_1.pdf", $headers);
    }
}
```

### Set PDF-Options

[](#set-pdf-options)

If you want to make further settings to the internal PDF engine, then you can change further settings using a callback. The usage is as follows:

#### Set options before instanciating the internal PDF-Engine (`setPdfPreInitCallback`)

[](#set-options-before-instanciating-the-internal-pdf-engine-setpdfpreinitcallback)

```
use horstoeko\zugferdvisualizer\ZugferdVisualizer;
use Mpdf\Mpdf;

$visualizer = new ZugferdVisualizer(static::$document);
$visualizer->setDefaultTemplate();
$visualizer->setPdfPreInitCallback(function (array $config, ZugferdVisualizer $visualizer) {
    $config["orientation"] = "L";
    return $config;
});
```

#### Set options after instanciating the internal PDF-Engine (`setPdfRuntimeInitCallback`)

[](#set-options-after-instanciating-the-internal-pdf-engine-setpdfruntimeinitcallback)

```
use horstoeko\zugferdvisualizer\ZugferdVisualizer;
use Mpdf\Mpdf;

$visualizer = new ZugferdVisualizer(static::$document);
$visualizer->setDefaultTemplate();
$visualizer->setPdfRuntimeInitCallback(function (Mpdf $mpdf, ZugferdVisualizer $visualizer) {
    $mpdf->pdf_version = "1.7";
});
```

#### Working with custom fonts

[](#working-with-custom-fonts)

If 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:

```
use horstoeko\zugferdvisualizer\ZugferdVisualizer;
use Mpdf\Mpdf;

$visualizer = new ZugferdVisualizer(static::$document);
$visualizer->addPdfFontDirectory('/var/fonts1/');
$visualizer->addPdfFontDirectory('/var/fonts2/');
```

Next, you need to define the font properties:

- The first parameter sets the name of the font-family
- Thé second parameter sets the type of the font
    - R - Regular
    - I - Italic
    - B - Bold
    - BI - Bold &amp; Italic
- The third parameter sets the filename under which the font can be found in the specified font-directories

```
$visualizer->addPdfFontData('comicsans', 'R', 'comic.ttf');
$visualizer->addPdfFontData('comicsans', 'I', 'comici.ttf');
```

If you want to set a custom font as the default font, you can use the following method:

```
$visualizer->setPdfFontDefault("comicsans");
```

You can also use the name of the font family in the style attribute of any HTML elements in your template:

```
Text in Comic Sans
```

For more configuration options, please consult the documentation of [mPdf](https://mpdf.github.io/configuration/configuration-v7-x.html)

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance66

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~118 days

Total

11

Last Release

487d ago

PHP version history (3 changes)v1.0.0PHP ^7.3|^7.4|^8.0|^8.1|^8.2|^8.3

v1.0.8PHP ^7.3|^7.4|^8

v1.0.10PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/24de09032b9a378d782bb7eac3f60914f64967e5a68d51527439dcf7c51711ba?d=identicon)[horstoeko](/maintainers/horstoeko)

---

Top Contributors

[![horstoeko](https://avatars.githubusercontent.com/u/2326713?v=4)](https://github.com/horstoeko "horstoeko (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")

---

Tags

electronic-invoiceselectronic-invoicingen16931factur-xphpphp7php8vizualisationxrechnungxrechnung-visualizationzugferd

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/horstoeko-zugferdvisualizer/health.svg)

```
[![Health](https://phpackages.com/badges/horstoeko-zugferdvisualizer/health.svg)](https://phpackages.com/packages/horstoeko-zugferdvisualizer)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[phiki/phiki

Syntax highlighting using TextMate grammars in PHP.

3573.0M23](/packages/phiki-phiki)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[torchlight/engine

The PHP-based Torchlight code annotation and rendering engine.

655.7k4](/packages/torchlight-engine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
