How to use a module written in java to be used in scala playframework project(for ex pdf module in playframework only available for java)
1 Answer
I don't think there is a clear distinction between java/scala modules in play 2.x, although you may experience some problems running modules labeled as "scala" in java project and vice versa.
I have used pdf module just OK in scala project, my dependency is "pdf" % "pdf_2.10" % "0.5",
Following Action renders pdf from sample template named testPdf:
def renderSamplePdf() = Action {
SimpleResult(
header = ResponseHeader(OK, Map(
CONTENT_DISPOSITION -> (s"""attachment; filename="document.pdf"; filename*=UTF-8''""" + java.net.URLEncoder.encode("document.pdf", "UTF-8").replace("+", "%20")),
CONTENT_TYPE -> "application/pdf")),
body = Enumerator(PDF.toBytes(views.html.testPdf())))
}
Note that this module version has some bugs, like it produces errors when you use absolute positioned elements.
1 Comment
immutable
in play 2.3 SimpleResult renamed as Result...github.com/playframework/playframework/pull/2526