An open API service indexing awesome lists of open source software.

https://github.com/tecsiaron/ublrenderer

PHP Library to convert RO eFactura UBL/ZIP files to HTML/PDF
https://github.com/tecsiaron/ublrenderer

anaf anaf-ro-efact e-factura efactura php php8 ro-e-factura ubl

Last synced: 6 months ago
JSON representation

PHP Library to convert RO eFactura UBL/ZIP files to HTML/PDF

Awesome Lists containing this project

README

          

UBLRenderer
===========

STILL IN TESTING PHASE
Should not be used in production
PHP Library to convert RO eFactura UBL/ZIP files to HTML/PDF*
Check [Sample PDF](https://github.com/TecsiAron/ublrenderer/blob/main/sample_output/sample.pdf) and [Sample HTML](https://github.com/TecsiAron/ublrenderer/blob/main/sample_output/sample.html)
Uses Twig for templating and supports user defined templates.
Requirements:
- php 8.2 or newer
- ext-xmlreader
- ext-bcmath
- ext-zip
- ext-libxml

Instalation:
```
composer require tecsiaron/ublrenderer
```
Usage in shell:
```
php vendor/bin/ubl2html.php
```
Simple usage in php (with XML file):
```PHP
$content=file_get_contents("path_to.xml");
$renderer = new UBLRenderer($content);
$renderer->WriteFile();
```
Simple usage with ANAF ZIP
```PHP
$content=UBLRenderer::LoadUBLFromZip("test.zip")->ubl;
$renderer = new UBLRenderer($content);
$renderer->WriteFile();
```
In both of the above cases the file will be written to vendor/tecsiaron/ublrenderer/output
To specify where files are written call WriteFile (or WriteFiles) like this:
```PHP
$renderer->WriteFiles(new HTMLFileWriter("path_to_output.html"));
```
Advanced usage:
```PHP
// get the contents of the XML
$renderer = new UBLRenderer($content);
$invoice=$renderer->ParseUBL();
$validation=$invoice->CanRender();
$validationFailReason="Validation failed:\n";
if(is_array($validation))
{
echo "Failed to render invoice: ". implode("\n", $validation)
}
else
{
$html=$renderer->CreateHTML(invoice);
}
```
*For PDF support install ublrenderer-pdf and use PDFWriter
```PHP
composer require tecsiaron/ublrenderer-pdf
```