[2.0] Install iText PDF

523 views
Skip to first unread message

tmueller

unread,
Mar 15, 2012, 4:41:11 PM3/15/12
to play-framework
Hello,

I have been experimenting with 2.0 and really like it so far. One
requirement of many is to export various items to a PDF. I am
struggling a bit trying to wrap my head around integrating this into
my application.

Here is my build.scala file:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

val appName = "MyApp"
val appVersion = "1.0-SNAPSHOT"

val appDependencies = Seq(
// Add your project dependencies here,
"http://maven.apache.org/settings.html#Repositories" % "iText"
% "5.1.3"
)

val main = PlayProject(appName, appVersion, appDependencies,
mainLang = JAVA).settings(
// Add your own project settings here

)

}

I get a build error about not finding the dependency. It appears it
doesn't like the URL. Any tutorials on how to use a PDF component or
at the very least on how to add modules to the build file.

Thanks,

Todd

Ludovico Fischer

unread,
Mar 15, 2012, 5:26:25 PM3/15/12
to play-fr...@googlegroups.com


On Thursday, 15 March 2012 21:41:11 UTC+1, tmueller wrote:
Hello,

I have been experimenting with 2.0 and really like it so far. One
requirement of many is to export various items to a PDF. I am
struggling a bit trying to wrap my head around integrating this into
my application.

Here is my build.scala file:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "MyApp"
    val appVersion      = "1.0-SNAPSHOT"

    val appDependencies = Seq(
      // Add your project dependencies here,
        "http://maven.apache.org/settings.html#Repositories" % "iText"
% "5.1.3"
    )

    val main = PlayProject(appName, appVersion, appDependencies,
mainLang = JAVA).settings(
      // Add your own project settings here

    )

}

The format of the dependency is wrong. You should use the the Maven groupId % artifactId % version format. For iText, your Maven configuration would be this:

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.1.3</version>
</dependency>
 
and so it becomes this in SBT (the build tool Play 2.0 uses) "com.itextpdf" % "itextpdf"  % "5.1.3"

The official SBT tutorial can be found here:

https://github.com/harrah/xsbt/wiki/Getting-Started-Welcome

Ludovico

tmueller

unread,
Mar 15, 2012, 5:42:49 PM3/15/12
to play-framework
Thanks Ludovico!

I was close to getting it right.

tmueller

unread,
Mar 15, 2012, 7:05:24 PM3/15/12
to play-framework
Hi Ludovico,

I have another question. The dependency was downloaded successfully
and I was able to compile the project. When I try to run a simple test
to render a PDF i get this error:


The import com.itextpdf cannot be resolved


import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;


How do I clear this error with Play managing this dependency?
Reply all
Reply to author
Forward
0 new messages