Skip to content


Folders and files

Last commit message
Last commit date

Latest commit


Repository files navigation

Play 2.8.x PDF module

Sonatype maven

This module helps generating PDF documents dynamically from your Play! web application. It simply renders your HTML- and CSS-based templates to PDF. It is based on the Flying Saucer library, which in turn uses iText for PDF generation. This project is a fork of .


You can use a standard Play! scala template like this one:

@(message: String)

@main("Welcome to Play 2") {
    Image: <img src="/public/images/favicon.png"/><br/>
    Hello world! <br/>
    @message <br/>

Then this template, after having imported it.innove.PdfGenerator, can simply be rendered as:

	public PdfGenerator pdfGenerator;

	public Result document() {
		return pdfGenerator.ok(document.render("Your new application is ready."), "http://localhost:9000");

where pdfGenerator.ok is a simple shorthand notation for:

	ok(pdfGenerator.toBytes(document.render("Your new application is ready."), "http://localhost:9000")).as("application/pdf")

Template rules

Templates must generate XHTML.

If the template is using an image, stylesheet, etc., it usually is loaded via an http call. The PDF modules tries to optimize that resource loading: If you specify the URI as a path into the classpath of your Play! app, the resource is loaded directly instead. See the above sample template for an example.

Of course you can link to CSS files in your class path also, but be aware not to use the media="screen"qualifier.

Fonts you use must be explicitely packaged with your app.

		<style type="text/css"><!--
		body {
			font-family: FreeSans;

Since the FreeSans font is not available to the java VM, you are required to add the corresponding font file, "FreeSans.ttf" to your Play! app. You can add your fonts with PdfGenerator.loadLocalFonts method, for example if you put the font in the folder /conf/fonts you load the font with:

pdfGenerator.loadLocalFonts(new String[]{"fonts/FreeSans.ttf"})


Currently, the module is hosted at Maven Central Repository. Therefore, including the following lines in your build.sbt will resolve it:

libraryDependencies ++= Seq(
      "it.innove" % "play2-pdf" % "x.x.x"


Play version play2-pdf vesion
2.8 1.10.x
2.7 1.9.x
2.6 1.8.x

After the next restart of Play!, the module is available. If you are using an IDE like Eclipse, remember to re-generate your project files.


If you need additional configuration, then modify your ApplicationModule accordingly:

public class ApplicationModule extends AbstractModule {
  protected void configure() {
  static class PdfGeneratorProvider implements Provider<PdfGenerator> {
    private final PdfGenerator pdfGenerator;

    public PdfGeneratorProvider(final Environment environment) {
      this.pdfGenerator = new PdfGenerator(environment);

    public PdfGenerator get() {
      return pdfGenerator;


Released under the MIT license; see the file LICENSE.