PD4ML v4 is a Java library (well, the .NET edition of PD4ML is still at v3, with the port of v4 pending), but the documents it produces are needed everywhere: in Django and Flask apps, PHP shops, ASP.NET services, Node.js backends and Rails applications. From today, all of them can use PD4ML v4 directly. Five new integrations bring its complete API – the same one the Java manual describes – to Python, PHP, .NET, Node.js and Ruby.

One install, no Java code

Each integration installs with the language’s own package manager:

  • Python: pip install pd4ml (PyPI)
  • PHP: composer require pd4ml/pd4ml-php (Packagist)
  • Node.js: npm install pd4ml (npm)
  • Ruby: gem install pd4ml (RubyGems)
  • .NET: the Pd4ml.Net NuGet package from pd4ml.com/net

Then one command – pd4ml install (in PHP projects vendor/bin/pd4ml install) – downloads the most recent PD4ML release and the Bouncy Castle libraries it needs for signing from the PD4ML Maven repository, checking every file against its published checksum. The Python, Node.js and Ruby integrations even do that on their own at first use. The only other requirement is a Java runtime (8 or later) on the machine.

The same API, in your language

The familiar PD4ML calls read naturally in each language. A PDF from an HTML string in Python:

import pd4ml

pd = pd4ml.PD4ML()
pd.setPageSize(pd4ml.PageSize.A4)
pd.read_html_string("<h1>Hello, PDF</h1><p>Generated with <b>PD4ML</b>.</p>")
pd.writePDF("hello.pdf")

The same in PHP:

use Pd4ml\PD4ML;
use Pd4ml\Java;

$pd = new PD4ML();
$pd->setPageSize(Java::PageSize()->A4);
$pd->readHtmlString('<h1>Hello, PDF</h1><p>Generated with <b>PD4ML</b>.</p>');
$pd->writePDF('hello.pdf');

In C#:

using Pd4mlNet;

var pd = new PD4ML();
pd.SetPageSize(PageSize.A4);
pd.ReadHtmlString("<h1>Hello, PDF</h1><p>Generated with <b>PD4ML</b>.</p>");
pd.WritePDF("hello.pdf");

In Node.js:

const { PD4ML, PageSize } = require('pd4ml');

const pd = new PD4ML();
pd.setPageSize(PageSize.A4);
pd.readHtmlString('<h1>Hello, PDF</h1><p>Generated with <b>PD4ML</b>.</p>');
pd.writePDF('hello.pdf');

And in Ruby:

require 'pd4ml'

pd = Pd4ml::PD4ML.new
pd.set_page_size(Pd4ml::PageSize::A4)
pd.read_html_string('<h1>Hello, PDF</h1><p>Generated with <b>PD4ML</b>.</p>')
pd.write_pdf('hello.pdf')

Beyond “hello world”, every feature of PD4ML is there: PDF/A and PDF/UA, ZUGFeRD and Factur-X invoices, DOCX and RTF output, page images, headers and footers with page numbers, watermarks, bookmarks, fonts, encryption and permissions, and the PDF toolkit for merging, overlaying and signing existing documents. Each integration also adds what makes it feel at home: file paths, byte strings and streams instead of Java I/O, the language’s own error handling, callbacks as progress listeners – and a command line tool for quick conversions.

A note on .NET

PD4ML for .NET is a temporary solution. Like the other integrations, it runs the Java PD4ML in a small bridge process next to your application – so it needs a Java runtime, but in return gives .NET applications today’s PD4ML: the same features, the same output and the same releases as the Java library. The native PD4ML.NET, a fully managed port, is based on PD4ML v3; its port of v4 is pending, and when it is ready, it will take this package’s place. Until then, Pd4ml.Net is the way to use PD4ML v4 from C# and the other .NET languages, with typed classes for the whole API.

Documentation

Every integration comes with a user guide: installation, how it works, use cases with runnable code for the common tasks, tips, troubleshooting and an API reference. They are in the new Integrations section of the PD4ML documentation:

For PD4ML itself – layout, page formats, fonts, standards – the guides refer to the PD4ML Programmer’s Manual, whose API they all share. The sources of the PHP, Node.js and Ruby packages are on GitHub: pd4ml-php, pd4ml-node, pd4ml-ruby.

Availability

All five integrations are available now. They work with the current PD4ML release, and they pick up new PD4ML releases with a single pd4ml install. As with PD4ML for Java, an evaluation runs without a license, with watermarked output; your existing PD4ML license applies to them as well.

Questions, or a framework you would like to see covered? Let us know – we’d like to hear how you use PD4ML from your language.