All Projects → hhandoko → play2-scala-pdf

hhandoko / play2-scala-pdf

Licence: other
A PDF module for Play Framework 2 (Scala)

Programming Languages

scala
5932 projects
HTML
75241 projects
CSS
56736 projects
shell
77523 projects

Projects that are alternatives of or similar to play2-scala-pdf

Openpdf
OpenPDF is a free Java library for creating and editing PDF files with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository. ⛺
Stars: ✭ 2,174 (+8596%)
Mutual labels:  itext, openpdf
Play Mailer
Play mailer plugin
Stars: ✭ 243 (+872%)
Mutual labels:  play-framework
Lila
♞ lichess.org: the forever free, adless and open source chess server ♞
Stars: ✭ 10,315 (+41160%)
Mutual labels:  play-framework
Play Redis
Play framework 2 cache plugin as an adapter to redis-server
Stars: ✭ 152 (+508%)
Mutual labels:  play-framework
Play2 Html5tags
HTML5 form tags module for Play Framework
Stars: ✭ 101 (+304%)
Mutual labels:  play-framework
Play Json Derived Codecs
Stars: ✭ 179 (+616%)
Mutual labels:  play-framework
Vos backend
vangav open source - backend; a backend generator (generates more than 90% of the code needed for big scale backend services)
Stars: ✭ 71 (+184%)
Mutual labels:  play-framework
play-docker-aws-tutorial
101 tutorial: How to deploy Play application to Amazon Lightsail (AWS) using Docker
Stars: ✭ 25 (+0%)
Mutual labels:  play-framework
React Play
Render React components in the Play Framework with JDK8's JavaScript engine
Stars: ✭ 216 (+764%)
Mutual labels:  play-framework
Play2 Crud
Simple CRUD & DAO implementation for play2
Stars: ✭ 146 (+484%)
Mutual labels:  play-framework
Api First Hand
API-First bootstrapping tool for building RESTful web services from a Swagger/OpenAPI spec
Stars: ✭ 138 (+452%)
Mutual labels:  play-framework
Play Pdf
A PDF module for the Play framework
Stars: ✭ 108 (+332%)
Mutual labels:  play-framework
Scala Play React Seed
❄️ Java Play 2.7.x + React seed project with full-fledged build process
Stars: ✭ 180 (+620%)
Mutual labels:  play-framework
Scala Play Angular Seed
🍀 Scala Play 2.7.x + Angular 8 with Angular CLI seed project with full-fledged build process
Stars: ✭ 85 (+240%)
Mutual labels:  play-framework
sbt-sass
A fork of the sbt-sass repository which seems to be abandoned.
Stars: ✭ 32 (+28%)
Mutual labels:  play-framework
Crypto Coin Alerts
An application that let you set alerts for the prices of several cryptocurrencies
Stars: ✭ 72 (+188%)
Mutual labels:  play-framework
Play Guard
Play2 module for rate limiting, based on token bucket algorithm
Stars: ✭ 123 (+392%)
Mutual labels:  play-framework
Pac4j
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 2,097 (+8288%)
Mutual labels:  play-framework
intelliroutes
Support for Play Routes in IntelliJ IDEA
Stars: ✭ 21 (-16%)
Mutual labels:  play-framework
play-silhouette-rest-mongo
Seed project for Play Framework 2.6 with Silhouette 5.0, exposing a REST API for sign-up and signin. ReactiveMongo + MongoDB used as a backing store.
Stars: ✭ 19 (-24%)
Mutual labels:  play-framework

License Master Build Status Maven Central

Play [2.4 to 2.8] PDF module

play2-scala-pdf is a Play Framework module to help generate PDF documents dynamically from Play Framework web application.

It simply renders Play Framework HTML and CSS-based view templates to PDF via Flying Saucer library, which uses OpenPDF, an open-source LGPL and MPL version of an older fork of iText for PDF generation.

Supported Play Framework and Scala Versions

The supported Scala and Play versions as follows:

Scala 2.10 Scala 2.11 Scala 2.12 Scala 2.13
Play 2.4 YES YES
Play 2.5 YES
Play 2.6 YES YES
Play 2.7 YES YES YES
Play 2.8 YES YES

Play Framework Java

If you are using Play Framework Java, check out https://github.com/innoveit/play2-pdf.

play2-scala-pdf is a fork of the project above with the aim to reduce the final distribution size for Play Framework Scala projects by rebasing the module to Play Framework Scala core (i.e. avoid including Play Framework Java additions in Play Framework Scala projects).

Installation

Create a PDF generator factory method in your application's Guice module:

@Provides
def providePdfGenerator(): PdfGenerator = {
  val pdfGen = new PdfGenerator()
  pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf"))
  pdfGen
}

Currently, the module is hosted at Maven Central Repository. Include the following lines in build.sbt, then reload SBT to resolve and enable the module:

libraryDependencies ++= Seq(
  ...
  "com.hhandoko" %% "play28-scala-pdf" % "4.3.0" // Use `play27-scala-pdf` for Play 2.7.x apps, etc.
)

Remember to add Sonatype snapshots repository to use snapshot releases:

resolvers ++= Seq(
  Resolver.sonatypeRepo("snapshots")
)

NOTE: If you are using an IDE like Eclipse, remember to re-generate your project files.

Usage

You can use a standard Play Framework Scala template like this one:

@(message: String)

@main("Example Page") {
    Image: <img src="/public/images/favicon.png"/><br/>
    Hello world! <br/>
    @message <br/>
}

Then this template, after having imported com.hhandoko.play.pdf.PdfGenerator, can simply be rendered as:

class HomeController @Inject() (pdfGen: PdfGenerator) extends Controller {

    def examplePdf = Action { pdfGen.ok(views.html.example(), "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

Please observe the following constraints to avoid issues when using this module:

  • Avoid using media="screen" qualifier on linked CSS in <head>, otherwise you must provide specific print stylesheets (i.e. media="print")
  • Non-system fonts must be loaded explicitly (see below for example)
  • External assets such as images need to be loaded as base64-encoded string
  • External such as stylesheets will be loaded as per normal HTML page load

NOTE: If the specified URI is a path into Play Framework app classpath, the resource is loaded directly instead. See the above sample template for an example.

Fonts can be loaded by invoking PdfGenerator.loadLocalFonts method. For example:

  • if fonts are stored under /conf/fonts (or other project path mapped to the classpath),
  • it can be loaded by invoking pdfGenerator.loadLocalFonts(Seq("fonts/FreeSans.ttf"))

NOTE: Non-system fonts in this context refers to WebFonts, fonts not available to the Java VM, or other fonts not included as part of normal OS distribution

Contributing

We follow the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Commit changes to a branch in your fork (use snake_case convention):
    • For technical chores, use chore/ prefix followed by the short description, e.g. chore/do_this_chore
    • For new features, use feature/ prefix followed by the feature name, e.g. feature/feature_name
    • For bug fixes, use bug/ prefix followed by the short description, e.g. bug/fix_this_bug
  3. Rebase or merge from "upstream"
  4. Submit a PR "upstream" with your changes

Please read CONTRIBUTING for more details.

License

The MIT License (MIT)

Original   - Copyright (c) 2014 Jöerg Viola, Marco Sinigaglia
Derivative - Copyright (c) 2016 - 2020 play2-scala-pdf Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

play2-scala-pdf is released under the MIT license. See the LICENSE file for further details.

Open Sans font by Steve Matteson is released under the Apache 2 license. See the Open Sans Google Fonts page for further details.

Play Framework logo is a trademark of Lightbend.

Releases

https://github.com/hhandoko/play2-scala-pdf/releases

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].