We’re excited to announce the support of Preprocessors to HTML2PDF Web Service. Which essentially makes this a Markup Language To PDF Web Service! Starting today you can use a wide range of markup languages to create PDF’s, not just HTML.
By introducing Preprocessors you can now convert Markdown (the original format), Textile, Pod and more to HTML. A special HTML Preprocessor has been added as well which essentially supercharges your HTML by adding support for several extra elements such as the current page number or total number of pages. And of course you can still style your PDF with CSS.
Using a header and/or footer has become easier now as well. To use these the HTML of the header, footer and content need to have a proper DOCTYPE and document layout. By using a Preprocessor this is now done for you.
We’re going to create a multi-paged PDF with a header and footer. The header will show our document title plus date and time. The footer will show the page number and total amount of pages.
First, lets write a small Markdown article (borrowed from https://markdown-it.github.io/).
Add some CSS.
And finally our Perl script to generate the PDF.
Before we continue, lets explain what’s going on with the preprocessor part. This is where we define how each provided content (content, header_content and footer_content) should be treated. By treating the header and footer as HTML we supercharge our HTML. The span elements with the date-, time-, page- and topage-classes serve an extra function now. These will show the current date, time, page number and total number of pages. We could’ve left out the preprocessor for the header and footer, but then these elements wouldn’t have done anything.
The content preprocessor is set to Markdown, which tells the preprocessor to treat the contents of content as Markdown and convert this to HTML first.
Finally, the style setting holds our custom stylesheet.
This will result in the following article.pdf. A multi-paged document with a header and footer.
Check out our documentation to learn more about this new feature.