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
- Host: GitHub
- URL: https://github.com/tecsiaron/ublrenderer
- Owner: TecsiAron
- License: apache-2.0
- Created: 2024-07-18T10:24:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-07T01:52:09.000Z (about 1 year ago)
- Last Synced: 2024-11-18T20:29:35.982Z (11 months ago)
- Topics: anaf, anaf-ro-efact, e-factura, efactura, php, php8, ro-e-factura, ubl
- Language: PHP
- Homepage:
- Size: 357 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
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
```