Comments (7)
I've just checked by re-running both Play 2.4 and 2.5 examples and they are running fine. Can you please share how are you running the examples? e.g. steps and commands in SBT.
Regarding passing a message, can you be more specific which part of the code / examples you are referring to? The example.scala.html
is a template with no constructor parameter args, e.g. @()
. Or perhaps, by message do you mean i18n messages?
from play2-scala-pdf.
More or less as the example.
I went for import it.innove.play.pdf.PdfGenerator instead.
But to start with I had
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)
libraryDependencies ++= Seq(
"com.builtamont" %% "play2-scala-pdf" % "1.6.1.P25"
)
A view:
@(message: String)
@main("Example Page") {
Image: <img src="/public/images/favicon.png"/><br/>
Hello world! <br/>
@message <br/>
}
And a home controller:
import com.builtamont.play.pdf.PdfGenerator
@Singleton
class HomeController @Inject() (pdfGen: PdfGenerator) extends Controller {
def examplePdf = Action { pdfGen.ok(views.html.example(), "http://localhost:9000") }
}
As the example, which don't compile, since the @message is not used in the call. But even with the message, it complains of having no default constructor
I would guess because the class is defined like this:
class PdfGenerator(env: Environment, val xhtml: Boolean = false)
And an env is required.
But for the play24 version it looked like this:
class PdfGenerator(val xhtml: Boolean = false) {
from play2-scala-pdf.
I just realised ApplicationModule.scala
was not committed as part of the example code, my bad.
The error makes sense now since it's trying to find a resolution for a PdfGenerator
instance (but it's missing). It should look something like below:
Play 2.4
package com.builtamont.modules
import com.google.inject.{AbstractModule, Provides}
import net.codingwell.scalaguice.ScalaModule
import com.builtamont.play.pdf.PdfGenerator
class ApplicationModule extends AbstractModule with ScalaModule {
/** Module configuration + binding */
def configure(): Unit = {}
/**
* Provides PDF generator implementation.
*
* @return PDF generator implementation.
*/
@Provides
def providePdfGenerator(): PdfGenerator = {
val pdfGen = new PdfGenerator()
pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf"))
pdfGen
}
}
Play 2.5
package com.builtamont.modules
import com.google.inject.{AbstractModule, Provides}
import net.codingwell.scalaguice.ScalaModule
import play.api.Environment
import com.builtamont.play.pdf.PdfGenerator
class ApplicationModule extends AbstractModule with ScalaModule {
/** Module configuration + binding */
def configure(): Unit = {}
/**
* Provides PDF generator implementation.
*
* @param env The current Play app Environment context.
* @return PDF generator implementation.
*/
@Provides
def providePdfGenerator(env: Environment): PdfGenerator = {
val pdfGen = new PdfGenerator(env)
pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf"))
pdfGen
}
}
They are both referenced within application.conf
:
play {
# Register the user modules
modules {
enabled += "com.builtamont.modules.ApplicationModule"
}
}
I'll update the repo later today.
from play2-scala-pdf.
Ah. Thanks!
from play2-scala-pdf.
Hi @pierce-build-user ,
I've pushed the repo update as a PR (refer to the above), please have a look. I have to run now but I'll merge the PR to master
sometime tonight (if all test passes). Let me know if the examples works OK for you now.
NOTE: Since the package name is updated, you'll need to update your application.conf
to reflect it as well.
from play2-scala-pdf.
Merged in master
.
from play2-scala-pdf.
Hi @pierce-build-user , let me know if you still have any problem... Otherwise I'll automatically close this in 48 hours.
from play2-scala-pdf.
Related Issues (17)
- Scala 2.12 version? HOT 4
- Chore - Update `flying-saucer` version HOT 1
- Chore - Update Play Framework 2.4 and 2.5 to latest HOT 1
- Chore - Publish Play Framework 2.6 module (Scala 2.11 and 2.12) HOT 1
- Replace dependency on itextpdf with openpdf HOT 5
- Failure to build: Could not find a suitable constructor in com.hhandoko.play.pdf.PdfGenerator. HOT 4
- Arabic characters not converted to PDF HOT 8
- Unable to add headers and footers to dynamic Pdf Genaration . HOT 2
- Is it possible to get rid of the margin on the generated PDF? HOT 1
- flyingsaucer update 9.1.18 HOT 4
- Scala 2.13 release HOT 4
- release for play 2.8.0 HOT 1
- There is way to put new page for Html templates concat inner PDF?
- Support for PDF encryption
- Vertical text
- Bundled `routes` file overrides root / parent project routes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from play2-scala-pdf.