{"id":19692773,"url":"https://github.com/hhandoko/play2-scala-pdf","last_synced_at":"2025-04-29T09:31:33.446Z","repository":{"id":57718054,"uuid":"65866381","full_name":"hhandoko/play2-scala-pdf","owner":"hhandoko","description":"A PDF module for Play Framework 2 (Scala)","archived":false,"fork":false,"pushed_at":"2020-09-09T04:02:13.000Z","size":16836,"stargazers_count":26,"open_issues_count":5,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-26T04:15:40.216Z","etag":null,"topics":["flying-saucer-library","itext","openpdf","pdf","play-framework","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhandoko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-17T01:37:28.000Z","updated_at":"2023-02-28T13:00:31.000Z","dependencies_parsed_at":"2022-08-24T07:20:45.437Z","dependency_job_id":null,"html_url":"https://github.com/hhandoko/play2-scala-pdf","commit_stats":null,"previous_names":["builtamont-oss/play2-scala-pdf"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhandoko%2Fplay2-scala-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhandoko%2Fplay2-scala-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhandoko%2Fplay2-scala-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhandoko%2Fplay2-scala-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhandoko","download_url":"https://codeload.github.com/hhandoko/play2-scala-pdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251473313,"owners_count":21595036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flying-saucer-library","itext","openpdf","pdf","play-framework","scala"],"created_at":"2024-11-11T19:14:22.260Z","updated_at":"2025-04-29T09:31:31.490Z","avatar_url":"https://github.com/hhandoko.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)\n[![Master Build Status](https://travis-ci.org/hhandoko/play2-scala-pdf.svg?branch=master)](https://travis-ci.org/hhandoko/play2-scala-pdf)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play28-scala-pdf_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play28-scala-pdf_2.13)\n\n# Play [2.4 to 2.8] PDF module\n\n`play2-scala-pdf` is a Play Framework module to help generate PDF documents dynamically from Play Framework web application.\n\nIt 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.\n\n### Supported Play Framework and Scala Versions\n\nThe supported Scala and Play versions as follows:\n\n|           | Scala 2.10 | Scala 2.11 | Scala 2.12 | Scala 2.13 |\n| --------- |:----------:|:----------:|:----------:|:----------:|\n| Play 2.4  | `YES`      | `YES`      |            |            |\n| Play 2.5  |            | `YES`      |            |            |\n| Play 2.6  |            | `YES`      | `YES`      |            |\n| Play 2.7  |            | `YES`      | `YES`      | `YES`      |\n| Play 2.8  |            |            | `YES`      | `YES`      |\n\n### Play Framework Java\n\nIf you are using Play Framework Java, check out [https://github.com/innoveit/play2-pdf](https://github.com/innoveit/play2-pdf).\n\n`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).\n\n## Installation\n\nCreate a PDF generator factory method in your application's Guice module:\n``` scala\n@Provides\ndef providePdfGenerator(): PdfGenerator = {\n  val pdfGen = new PdfGenerator()\n  pdfGen.loadLocalFonts(Seq(\"fonts/opensans-regular.ttf\"))\n  pdfGen\n}\n```\n\nCurrently, the module is hosted at Maven Central Repository. Include the following lines in ```build.sbt```, then reload SBT to resolve and enable the module:\n``` scala\nlibraryDependencies ++= Seq(\n  ...\n  \"com.hhandoko\" %% \"play28-scala-pdf\" % \"4.3.0\" // Use `play27-scala-pdf` for Play 2.7.x apps, etc.\n)\n```\n\nRemember to add Sonatype snapshots repository to use snapshot releases:\n``` scala\nresolvers ++= Seq(\n  Resolver.sonatypeRepo(\"snapshots\")\n)\n```\n\n*NOTE: If you are using an IDE like Eclipse, remember to re-generate your project files.*\n\n## Usage\n\nYou can use a standard Play Framework Scala template like this one:\n``` html\n@(message: String)\n\n@main(\"Example Page\") {\n    Image: \u003cimg src=\"/public/images/favicon.png\"/\u003e\u003cbr/\u003e\n    Hello world! \u003cbr/\u003e\n    @message \u003cbr/\u003e\n}\n```\n\nThen this template, after having imported ```com.hhandoko.play.pdf.PdfGenerator```, can simply be rendered as:\n``` scala\nclass HomeController @Inject() (pdfGen: PdfGenerator) extends Controller {\n\n    def examplePdf = Action { pdfGen.ok(views.html.example(), \"http://localhost:9000\") }\n\n}\n```\n\nwhere ```pdfGenerator.ok``` is a simple shorthand notation for:\n``` scala\nok(pdfGenerator.toBytes(document.render(\"Your new application is ready.\"), \"http://localhost:9000\")).as(\"application/pdf\")\n```\n\n## Template rules\n\nPlease observe the following constraints to avoid issues when using this module:\n\n  - Avoid using `media=\"screen\"` qualifier on linked CSS in `\u003chead\u003e`, otherwise you must provide specific print stylesheets (i.e. `media=\"print\"`)\n  - Non-system fonts must be loaded explicitly (see below for example)\n  - External assets such as images need to be loaded as base64-encoded string\n  - External such as stylesheets will be loaded as per normal HTML page load\n\n*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.*\n\nFonts can be loaded by invoking `PdfGenerator.loadLocalFonts` method. For example:\n\n  - if fonts are stored under `/conf/fonts` (or other project path mapped to the classpath),\n  - it can be loaded by invoking `pdfGenerator.loadLocalFonts(Seq(\"fonts/FreeSans.ttf\"))`\n\n*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*\n\n## Contributing\n\nWe follow the \"[fork-and-pull]\" Git workflow.\n\n  1. Fork the repo on GitHub\n  1. Commit changes to a branch in your fork (use `snake_case` convention):\n     - For technical chores, use `chore/` prefix followed by the short description, e.g. `chore/do_this_chore`\n     - For new features, use `feature/` prefix followed by the feature name, e.g. `feature/feature_name`\n     - For bug fixes, use `bug/` prefix followed by the short description, e.g. `bug/fix_this_bug`\n  1. Rebase or merge from \"upstream\"\n  1. Submit a PR \"upstream\" with your changes\n\nPlease read [CONTRIBUTING] for more details.\n\n## License\n\n```\nThe MIT License (MIT)\n\nOriginal   - Copyright (c) 2014 Jöerg Viola, Marco Sinigaglia\nDerivative - Copyright (c) 2016 - 2020 play2-scala-pdf Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n`play2-scala-pdf` is released under the MIT license. See the [LICENSE] file for further details.\n\n`Open Sans` font by [Steve Matteson] is released under the Apache 2 license. See the [Open Sans Google Fonts] page for further details.\n\n`Play Framework` logo is a trademark of [Lightbend].\n\n## Releases\n\nhttps://github.com/hhandoko/play2-scala-pdf/releases\n\n[CONTRIBUTING]: CONTRIBUTING.md\n[Flying Saucer library]: https://github.com/flyingsaucerproject/flyingsaucer\n[fork-and-pull]: https://help.github.com/articles/using-pull-requests\n[LICENSE]: LICENSE\n[Lightbend]: https://www.lightbend.com/company\n[OpenPDF]: https://github.com/LibrePDF/OpenPDF\n[Open Sans Google Fonts]: https://fonts.google.com/specimen/Open+Sans\n[Steve Matteson]: https://twitter.com/@SteveMatteson1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhandoko%2Fplay2-scala-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhandoko%2Fplay2-scala-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhandoko%2Fplay2-scala-pdf/lists"}