PDF Invoice generator

Converting Your Invoices to PDF with PDFreactor

This article will provide answers to the following questions:

  • Can I create an invoice with PDFreactor?
  • How to generate an invoice from a document or template?
  • Can I use PHP or JavaScript to create an invoice?
  • Can I create e-invoices with PDFreactor?
  • Is there a demo for the dynamic creation of invoices?

Using PDFreactor to Generate Invoices

PDFreactor was designed as a component for the conversion of HTML to PDF with a focus on high quality, fidelity and pagination support. As such, PDFreactor is ideally suited for integration in applications where invoices are already available in HTML format. This includes multi-channel publishing solutions as well as any web application where invoices can be viewed in the browser.

All you need is to install PDFreactor as a Web Service using one of the installation packages available on the download section, then you can start integrating into your application. Installer packages are available for Windows, macOS, Linux and Unix. PDFreactor comes with support for a number of APIs such as JavaScript, PHP, C+ or REST, as detailed here.

If your invoice is populated or built dynamically through use of JavaScript (incl. XMLHttpRequests), PDFreactor has got you covered, since it supports JavaScript as well as a number of popular JavaScript Frameworks out of the box. For details, please see Convert HTML + JavaScript.

PDFreactor is not limited to any particular type of invoice. As long as a document can be represented by HTML, CSS and JavaScript, you can use PDFreactor as a generator for any kind of document including but not limited to:

  • Proforma invoices.
  • Tax forms.
  • Bills.
  • Receipts.
  • Order Confirmations.

Creating an Invoice from an HTML Template

If your invoice is available as an HTML document in your system (incl. documents generated from data retrieved from a server-side scripting language such as C# or PHP), you basically just need to configure the URL for this document as input for PDFreactor, which will handle the conversion automatically. Note that if the document requires authentication, you also have the option of providing the document content as a String to PDFreactor.

Generating an Invoice with PHP

As said above, the list of wrappers available for the PDFreactor Web Service includes PHP. See below for an example on how to convert an HTML document or template to PDF using PHP:

// Include PDFreactor class 
require_once("PDFreactor.class.php");
use com\realobjects\pdfreactor\webservice\client\PDFreactor as PDFreactor;

// Create new PDFreactor instance 
$pdfReactor = new PDFreactor("https://cloud.pdfreactor.com/service/rest");
$config = array(
    // Specify the input document 
    "document"=>"http://myserver.com/customer/2324092/invoice/29334.html"
);

// Render document and save result to $result 
$result = null;
try {
    $result = $pdfReactor->convertAsBinary($config);
    header("Content-Type: application/pdf");
    echo $result;
} catch (Exception $e) {
    echo "An Error Has Occurred";
    echo $e->getMessage();
}

Generating an Invoice with JavaScript

Here’s an example on how to convert an HTML document with PDFreactor using the JavaScript API:

var pdfReactor = new PDFreactor("https://cloud.pdfreactor.com/service/rest");

// Create a new PDFreactor configuration object
var config = {
    // Specify the document the invoice will be generated from
    document: "http://www.myserver.com/customer/2324092/invoice/29334.html"
}

// Render document and save result
pdfReactor.convert(config, function(result) {
    // do something with the result, e.g. set it as the src of an IFRAME to display the PDF in the same page
    document.getElementById("result").src = "data:application/pdf;base64," + result.document;
}, function(error) {
    document.body.innerHTML = "An Error Has Occurred: " + error;
});   

Designing Invoice Templates for JavaScript with HTML + CSS

If your invoices are not available as complete documents yet, you can design a simple HTML template that will either be populated dynamically via JavaScript or XMLHttpRequests, or prepopulate it using your scripting language of choice before passing it to PDFreactor. Your templates and documents can be enriched through print styles sheets designed specifically for paged media. This allows you to specify individual page margins, break styles, and leverage the use of running elements for your documents. For an overview of all CSS properties supported by PDFreactor, please see CSS Support.

Moreover, since PDFreactor supports accessility features incl. and PDF/A compliance, your invoices will do so too.

Leverage PDFreactor to Create E-Invoices (incl. ZUGFeRD Support)

If you have an invoicing system or are planning to generate invoices for your web app based on your customer’s shopping basket, PDFreactor is the perfect companion for all your printing needs.

E-Invoicing

Generally speaking, the e-invoicing functionality covered by PDFreactor is the part of actually printing data to PDF. PDFreactor does not include any functionality that keeps track of financial transactions, accounting, etc. It is not a replacement for an ERP system.

That said, certain e-invoices or digital invoices often have specific requirements with regards to PDF documents: certain standards require PDF documents to also include a machine-readable version of the invoice (in XML format or otherwise) to be attached, or the PDF itself to subscribe to certain format or document restrictions, all of which can be covered by PDFreactor.

ZUGFeRD

In addition, an optional add-on for the creation of e-invoices in the ZUGFeRD format in particular is available for PDFreactor. ZUGFeRD is a standard developed by FeRD (Forum for Electronic Invoicing in Germany) to standardize the process of creating and sharing electronic invoices. The PDFreactor ZUGFeRD e-invoice add-on provides a JavaScript API which allows to convert the data from your original HTML based invoice into standardized structured invoice data in XML format. This XML will then automatically be attached to the PDF created by PDFreactor.

Dynamic Invoice Demo

A basic example that shows how PDFreactor can be used to generate invoices from data injected into a template through user input is available on the PDFreactor website here:

Dynamically Generate an Invoice