Giter Club home page Giter Club logo

Comments (7)

hhandoko avatar hhandoko commented on May 18, 2024

Hi @pierce-build-user,

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.

pierce-build-user avatar pierce-build-user commented on May 18, 2024

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.

hhandoko avatar hhandoko commented on May 18, 2024

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.

pierce-build-user avatar pierce-build-user commented on May 18, 2024

Ah. Thanks!

from play2-scala-pdf.

hhandoko avatar hhandoko commented on May 18, 2024

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.

hhandoko avatar hhandoko commented on May 18, 2024

Merged in master.

from play2-scala-pdf.

hhandoko avatar hhandoko commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.