Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A PDF module for Play 2.0
Java Scala
Branch: master
Latest commit c2531a @benjohnde Update
Failed to load latest commit information.
module Merge branch 'master' of
samples/pdf-sample clean up naming
LICENSE License added Update

Play 2.4.3 PDF module

This README is a bit outdated and will get some love in the near future.

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.


I have provided a simple example application at

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

@(message: String)

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

Then this template, after having imported util.pdf.PDF, can simply be rendered as:

    public static Result document() {
        return PDF.ok(document.render("Your new application is ready."));

where PDF.ok is a simple shorthand notation for:

    ok(PDF.toBytes(document.render("Your new application is ready."))).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. The module adds /conf/resources/fonts to the list of directories searched for font files.


Currently, the module is hosted at Therefore, including the following lines in your Build.scala will resolve it:

val appDependencies = Seq(
      "de.joergviola" %% "play-pdf" % "0.6-SNAPSHOT"
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
  resolvers += Resolver.url("Violas Play Modules", url(""))(Resolver.ivyStylePatterns)

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.


Released under the MIT license; see the file LICENSE.

Something went wrong with that request. Please try again.