hhandoko / play2-scala-pdf Goto Github PK
View Code? Open in Web Editor NEWA PDF module for Play Framework 2 (Scala)
License: Other
A PDF module for Play Framework 2 (Scala)
License: Other
Play 2.7.3 is compiled against Scala 2.13, and scalatestplus-play
is also available for 2.13, so I think it should be possible to release play2-scala-pdf
as well.
Thanks!
Play Framework 2.5 branch's latest version is 2.5.15
and 2.4 branch is 2.4.11
. The module and examples are several patch versions behind.
The module and examples are updated to the latest Play Framework version.
The latest flying-saucer
library is available, which fixes issues with broken links to older bouncycastle
dependencies.
Update flying-saucer
to version9.1.6
on both modules (Play 2.4 and 2.5).
Aabic Charaters are not converted to pdf format
Arabic text is left blank on pdf file, while it's correctly displayed on html format:
1- set an exemle.scala.html with arabic characters
2- Load an arabic font in ApplicationModule.scala using pdfGen.loadLocalFonts(Seq("fonts/TAHOMA_0.TTF"))
-->
Application pages should be able to be accessed normally after importing the PDF generation library.
Play framework shows Action not found
info page instead of the desired application page.
A simple project should build.
Could not find a suitable constructor in com.hhandoko.play.pdf.PdfGenerator.
Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument
constructor that is not private.
at com.hhandoko.play.pdf.PdfGenerator.class(PdfGenerator.scala:53)
build.sbt
name := "testpdf"
version := "1.0"
lazy val `testpdf` = (project in file(".")).enablePlugins(PlayScala)
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
scalaVersion := "2.12.2"
libraryDependencies ++= Seq( jdbc , ehcache , ws , specs2 % Test , guice,
"com.hhandoko" %% "play2-scala-pdf" % "3.0.0.P26" )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
HomeController.scala
package controllers
import com.hhandoko.play.pdf.PdfGenerator
import javax.inject._
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class HomeController @Inject()(pdfGen:PdfGenerator,cc: ControllerComponents) extends
AbstractController(cc) {
/**
* Create an Action to render an HTML page with a welcome message.
* The configuration in the `routes` file means that this method
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
def index = Action {
pdfGen.ok(views.html.index("Your new application is ready."),"http://localhost:9000")
}
}
Running you example, I would expect it to work, instead I experience the following exception:
Could not find a suitable constructor in com.builtamont.play.pdf.PdfGenerator. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at com.builtamont.play.pdf.PdfGenerator.class(PdfGenerator.scala:53)
while locating com.builtamont.play.pdf.PdfGenerator
Also, this coed does not compile since your "example" template expect a message, and you call it without.
Working code, or updated documentation that explain the use of inject into HomeController
Hi,
I'm trying to generate a PDF using this HTML:
<html>
<head>
<style>
body {background-color: grey; margin: 0 }
</style>
</head>
<body>
Howdy!
<br/><br/>
You may not know it yet, but this is best PDF in the world!
<br/><br/>
Keep it green!
</body>
</html>
and feeding it into the PdfGenerator.toBytes
method. However, the PDF that gets generate always has a white margin around the body.
For this specific toy example, I wanted the whole page to have a grey background. Is this possible? Maybe I'm missing any specific CSS (definitely not my strongest asset).
Thanks!
Hi!
Do you have any plans for releasing the version for Scala 2.12? It seems that the library already works fine with Play 2.6, but a proper release that supports new Scala would be great.
Thanks!
Play Framework 2.6
was published recently with new internals (Akka HTTP-based).
Create a new Play 2.6
-compatible module and examples with cross publishing with Scala 2.11.8
and 2.12.1
.
It would be nice to add support for PDF encryption (which the underlying rendering library already implements).
I imagine this would be exposed via optional parameters to the toBytes
and toStream
generator methods.
Hi @hhandoko, there is way to put new page between Html templates in case of concat inner PDF?
Remove dependency on itextpdf, as its licensing requirements are restrictive. Replace with dependencies to openpdf.
https://github.com/LibrePDF/OpenPDF
build.sbt
libraryDependencies += "org.xhtmlrenderer" % "flying-saucer-pdf" % "9.1.6"
libraryDependencies += "org.xhtmlrenderer" % "flying-saucer-core" % "9.1.6"
libraryDependencies += "com.github.librepdf" % "openpdf" % "1.0.4"
Confirm all test cases complete successfully.
Hi, i would like to use the library (with Play 2.6 and scala 2.11) for creating PDFs. Unfortunately there is still a bug with box sizing which should be fixed with the flyingsaucer v9.1.18 release.
Can you update the version?
Write vertical text in @right-middle
.
I tried
@@right-middle {
content: "test;
writing-mode: vertical-rl;
}
But it doesn't work. Any suggestion?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.