diff --git a/README.md b/README.md index c497de2..d110b42 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![Master Build Status](https://travis-ci.org/hhandoko/play2-scala-pdf.svg?branch=master)](https://travis-ci.org/hhandoko/play2-scala-pdf) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play2-scala-pdf_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play2-scala-pdf_2.12) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play26-scala-pdf_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hhandoko/play26-scala-pdf_2.12) # Play [2.4 | 2.5 | 2.6] PDF module `play2-scala-pdf` is a Play Framework module to help generate PDF documents dynamically from Play Framework web application. -It simply renders Play Framework HTML and CSS-based view templates to PDF via [Flying Saucer library], which uses older, open-source version of iText for PDF generation. +It simply renders Play Framework HTML and CSS-based view templates to PDF via [Flying Saucer library], which uses [OpenPDF], an open-source LGPL and MPL version of an older fork of iText for PDF generation. ### Supported Play Framework and Scala Versions @@ -26,11 +26,21 @@ If you are using Play Framework Java, check out [https://github.com/innoveit/pla ## Installation +Create a PDF generator factory method in your application's Guice module: +``` scala +@Provides +def providePdfGenerator(): PdfGenerator = { + val pdfGen = new PdfGenerator() + pdfGen.loadLocalFonts(Seq("fonts/opensans-regular.ttf")) + pdfGen +} +``` + Currently, the module is hosted at Maven Central Repository. Include the following lines in ```build.sbt```, then reload SBT to resolve and enable the module: ``` scala libraryDependencies ++= Seq( ... - "com.hhandoko" %% "play2-scala-pdf" % "3.0.0.P26" // Use `3.0.0.P25` for Play 2.5.x apps or `3.0.0.P24 for Play 2.4.x apps + "com.hhandoko" %% "play26-scala-pdf" % "4.0.0" // Use `play25-scala-pdf` for Play 2.5.x apps or `play24-scala-pdf` for Play 2.4.x apps ) ``` @@ -144,5 +154,6 @@ https://github.com/hhandoko/play2-scala-pdf/releases [fork-and-pull]: https://help.github.com/articles/using-pull-requests [LICENSE]: LICENSE [Lightbend]: https://www.lightbend.com/company +[OpenPDF]: https://github.com/LibrePDF/OpenPDF [Open Sans Google Fonts]: https://fonts.google.com/specimen/Open+Sans [Steve Matteson]: https://twitter.com/@SteveMatteson1 diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..afa6365 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/examples/play24-example/build.sbt b/examples/play24-example/build.sbt index 3b29449..734b50f 100644 --- a/examples/play24-example/build.sbt +++ b/examples/play24-example/build.sbt @@ -24,9 +24,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf-example""" +name := """play24-scala-pdf-example""" -version := "1.0.0.P24" +version := "1.0.0" scalaVersion := "2.11.12" diff --git a/examples/play25-example/build.sbt b/examples/play25-example/build.sbt index 85c8cc7..e5d2f20 100644 --- a/examples/play25-example/build.sbt +++ b/examples/play25-example/build.sbt @@ -24,9 +24,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf-example""" +name := """play25-scala-pdf-example""" -version := "1.0.0.P25" +version := "1.0.0" scalaVersion := "2.11.12" diff --git a/examples/play26-example/build.sbt b/examples/play26-example/build.sbt index bd9a494..dfb9682 100644 --- a/examples/play26-example/build.sbt +++ b/examples/play26-example/build.sbt @@ -24,13 +24,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf-example""" +name := """play26-scala-pdf-example""" -version := "1.0.0.P26" +version := "1.0.0" -scalaVersion := "2.12.4" +scalaVersion := "2.12.6" -crossScalaVersions := Seq("2.11.12", "2.12.4") +crossScalaVersions := Seq("2.11.12", "2.12.6") libraryDependencies ++= Seq( guice, diff --git a/examples/play26-example/project/plugins.sbt b/examples/play26-example/project/plugins.sbt index 5db553c..745ed11 100644 --- a/examples/play26-example/project/plugins.sbt +++ b/examples/play26-example/project/plugins.sbt @@ -1,2 +1,2 @@ // Play Framework plugin -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.12") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.15") diff --git a/modules/play24/app/com/hhandoko/play/pdf/PdfGenerator.scala b/modules/play24/app/com/hhandoko/play/pdf/PdfGenerator.scala index 66743d2..6cf16e0 100644 --- a/modules/play24/app/com/hhandoko/play/pdf/PdfGenerator.scala +++ b/modules/play24/app/com/hhandoko/play/pdf/PdfGenerator.scala @@ -33,7 +33,7 @@ import java.io._ import scala.collection.mutable.ArrayBuffer import com.google.inject.Singleton -import com.itextpdf.text.pdf.BaseFont +import com.lowagie.text.pdf.BaseFont import nu.validator.htmlparser.dom.HtmlDocumentBuilder import org.apache.commons.io.{FilenameUtils, IOUtils} import org.w3c.tidy.Tidy diff --git a/modules/play24/app/com/hhandoko/play/pdf/PdfUserAgent.scala b/modules/play24/app/com/hhandoko/play/pdf/PdfUserAgent.scala index 920dd5b..825d17d 100644 --- a/modules/play24/app/com/hhandoko/play/pdf/PdfUserAgent.scala +++ b/modules/play24/app/com/hhandoko/play/pdf/PdfUserAgent.scala @@ -31,7 +31,7 @@ package com.hhandoko.play.pdf import java.io._ -import com.itextpdf.text.Image +import com.lowagie.text.Image import org.xhtmlrenderer.pdf.{ITextFSImage, ITextOutputDevice, ITextUserAgent} import org.xhtmlrenderer.resource.{CSSResource, ImageResource, XMLResource} diff --git a/modules/play24/build.sbt b/modules/play24/build.sbt index 7ba4539..a47d02c 100644 --- a/modules/play24/build.sbt +++ b/modules/play24/build.sbt @@ -24,11 +24,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf""" +import scala.io.Source + +name := """play24-scala-pdf""" organization := "com.hhandoko" -version := "3.0.1.P24-SNAPSHOT" +version := Source.fromFile("../../VERSION.txt").mkString.trim scalaVersion := "2.11.12" @@ -43,9 +45,11 @@ libraryDependencies ++= Seq( // - http://jtidy.sourceforge.net/ // - https://github.com/flyingsaucerproject/flyingsaucer // - https://about.validator.nu/htmlparser/ + // - https://jsoup.org/ "net.sf.jtidy" % "jtidy" % "r938", - "org.xhtmlrenderer" % "flying-saucer-pdf-itext5" % "9.1.12", + "org.xhtmlrenderer" % "flying-saucer-pdf-openpdf" % "9.1.12", "nu.validator.htmlparser" % "htmlparser" % "1.4", + "org.jsoup" % "jsoup" % "1.11.3" % Test, // ScalaTest + Play plugin // - http://www.scalatest.org/plus/play diff --git a/modules/play24/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala b/modules/play24/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala similarity index 82% rename from modules/play24/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala rename to modules/play24/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala index 4ac2bb5..5c23090 100644 --- a/modules/play24/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala +++ b/modules/play24/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala @@ -29,8 +29,9 @@ package com.hhandoko.play.pdf import java.io.InputStream import scala.io.Source -import com.itextpdf.text.pdf.PdfReader -import com.itextpdf.text.pdf.parser.PdfTextExtractor +import com.lowagie.text.pdf.PdfReader +import com.lowagie.text.pdf.parser.PdfTextExtractor +import org.jsoup.Jsoup import org.scalatestplus.play.{OneAppPerTest, PlaySpec} import play.twirl.api.Html @@ -42,50 +43,55 @@ class PdfGeneratorSpec extends PlaySpec with OneAppPerTest { def htmlStream: Option[InputStream] = app.resourceAsStream("example.html") def htmlString: String = htmlStream.fold("") { Source.fromInputStream(_).getLines().mkString("\n") } def html: Html = Html(htmlString) + val gen = new PdfGenerator() + def clean(html: String): String = Jsoup.parse(html).text() "PdfGenerator" should { val author = "play2-scala-pdf Contributors" val title = "`play2-scala-pdf` HTML to PDF example" val heading = "Hello, world!" - val gen = new PdfGenerator() "be able to create PDF given HTML string" in { val pdf = gen.toBytes(htmlString, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given HTML string and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(htmlString, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML" in { val pdf = gen.toBytes(html, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(html, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } } diff --git a/modules/play24/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala b/modules/play24/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala similarity index 100% rename from modules/play24/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala rename to modules/play24/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala diff --git a/modules/play25/app/com/hhandoko/play/pdf/PdfGenerator.scala b/modules/play25/app/com/hhandoko/play/pdf/PdfGenerator.scala index 9b05b97..bdd84f9 100644 --- a/modules/play25/app/com/hhandoko/play/pdf/PdfGenerator.scala +++ b/modules/play25/app/com/hhandoko/play/pdf/PdfGenerator.scala @@ -33,7 +33,7 @@ import java.io._ import scala.collection.mutable.ArrayBuffer import com.google.inject.Singleton -import com.itextpdf.text.pdf.BaseFont +import com.lowagie.text.pdf.BaseFont import nu.validator.htmlparser.dom.HtmlDocumentBuilder import org.apache.commons.io.{FilenameUtils, IOUtils} import org.w3c.tidy.Tidy diff --git a/modules/play25/app/com/hhandoko/play/pdf/PdfUserAgent.scala b/modules/play25/app/com/hhandoko/play/pdf/PdfUserAgent.scala index f767e1a..1b45256 100644 --- a/modules/play25/app/com/hhandoko/play/pdf/PdfUserAgent.scala +++ b/modules/play25/app/com/hhandoko/play/pdf/PdfUserAgent.scala @@ -31,7 +31,7 @@ package com.hhandoko.play.pdf import java.io._ -import com.itextpdf.text.Image +import com.lowagie.text.Image import org.xhtmlrenderer.pdf.{ITextFSImage, ITextOutputDevice, ITextUserAgent} import org.xhtmlrenderer.resource.{CSSResource, ImageResource, XMLResource} diff --git a/modules/play25/build.sbt b/modules/play25/build.sbt index de8946a..1086215 100644 --- a/modules/play25/build.sbt +++ b/modules/play25/build.sbt @@ -24,11 +24,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf""" +import scala.io.Source + +name := """play25-scala-pdf""" organization := "com.hhandoko" -version := "3.0.1.P25-SNAPSHOT" +version := Source.fromFile("../../VERSION.txt").mkString.trim scalaVersion := "2.11.12" @@ -43,9 +45,11 @@ libraryDependencies ++= Seq( // - http://jtidy.sourceforge.net/ // - https://github.com/flyingsaucerproject/flyingsaucer // - https://about.validator.nu/htmlparser/ + // - https://jsoup.org/ "net.sf.jtidy" % "jtidy" % "r938", - "org.xhtmlrenderer" % "flying-saucer-pdf-itext5" % "9.1.12", + "org.xhtmlrenderer" % "flying-saucer-pdf-openpdf" % "9.1.12", "nu.validator.htmlparser" % "htmlparser" % "1.4", + "org.jsoup" % "jsoup" % "1.11.3" % Test, // ScalaTest + Play plugin // - http://www.scalatest.org/plus/play diff --git a/modules/play25/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala b/modules/play25/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala similarity index 83% rename from modules/play25/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala rename to modules/play25/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala index 60fcbd2..acb10ca 100644 --- a/modules/play25/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala +++ b/modules/play25/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala @@ -29,8 +29,9 @@ package com.hhandoko.play.pdf import java.io.InputStream import scala.io.Source -import com.itextpdf.text.pdf.PdfReader -import com.itextpdf.text.pdf.parser.PdfTextExtractor +import com.lowagie.text.pdf.PdfReader +import com.lowagie.text.pdf.parser.PdfTextExtractor +import org.jsoup.Jsoup import org.scalatestplus.play.{OneAppPerTest, PlaySpec} import play.api.Environment @@ -45,6 +46,7 @@ class PdfGeneratorSpec extends PlaySpec with OneAppPerTest { def htmlString: String = htmlStream.fold("") { Source.fromInputStream(_).getLines().mkString("\n") } def html: Html = Html(htmlString) def gen = new PdfGenerator(env) + def clean(html: String): String = Jsoup.parse(html).text() "PdfGenerator" should { @@ -55,39 +57,43 @@ class PdfGeneratorSpec extends PlaySpec with OneAppPerTest { "be able to create PDF given HTML string" in { val pdf = gen.toBytes(htmlString, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given HTML string and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(htmlString, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML" in { val pdf = gen.toBytes(html, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(html, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } } diff --git a/modules/play25/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala b/modules/play25/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala similarity index 100% rename from modules/play25/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala rename to modules/play25/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala diff --git a/modules/play26/app/com/hhandoko/play/pdf/PdfGenerator.scala b/modules/play26/app/com/hhandoko/play/pdf/PdfGenerator.scala index 9b05b97..bdd84f9 100644 --- a/modules/play26/app/com/hhandoko/play/pdf/PdfGenerator.scala +++ b/modules/play26/app/com/hhandoko/play/pdf/PdfGenerator.scala @@ -33,7 +33,7 @@ import java.io._ import scala.collection.mutable.ArrayBuffer import com.google.inject.Singleton -import com.itextpdf.text.pdf.BaseFont +import com.lowagie.text.pdf.BaseFont import nu.validator.htmlparser.dom.HtmlDocumentBuilder import org.apache.commons.io.{FilenameUtils, IOUtils} import org.w3c.tidy.Tidy diff --git a/modules/play26/app/com/hhandoko/play/pdf/PdfUserAgent.scala b/modules/play26/app/com/hhandoko/play/pdf/PdfUserAgent.scala index f767e1a..1b45256 100644 --- a/modules/play26/app/com/hhandoko/play/pdf/PdfUserAgent.scala +++ b/modules/play26/app/com/hhandoko/play/pdf/PdfUserAgent.scala @@ -31,7 +31,7 @@ package com.hhandoko.play.pdf import java.io._ -import com.itextpdf.text.Image +import com.lowagie.text.Image import org.xhtmlrenderer.pdf.{ITextFSImage, ITextOutputDevice, ITextUserAgent} import org.xhtmlrenderer.resource.{CSSResource, ImageResource, XMLResource} diff --git a/modules/play26/build.sbt b/modules/play26/build.sbt index 5db5c2d..25b33e1 100644 --- a/modules/play26/build.sbt +++ b/modules/play26/build.sbt @@ -24,15 +24,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -name := """play2-scala-pdf""" +import scala.io.Source + +name := """play26-scala-pdf""" organization := "com.hhandoko" -version := "3.0.1.P26-SNAPSHOT" +version := Source.fromFile("../../VERSION.txt").mkString.trim -scalaVersion := "2.12.4" +scalaVersion := "2.12.6" -crossScalaVersions := Seq("2.11.12", "2.12.4") +crossScalaVersions := Seq("2.11.12", "2.12.6") libraryDependencies ++= Seq( guice, @@ -45,9 +47,11 @@ libraryDependencies ++= Seq( // - http://jtidy.sourceforge.net/ // - https://github.com/flyingsaucerproject/flyingsaucer // - https://about.validator.nu/htmlparser/ + // - https://jsoup.org/ "net.sf.jtidy" % "jtidy" % "r938", - "org.xhtmlrenderer" % "flying-saucer-pdf-itext5" % "9.1.12", + "org.xhtmlrenderer" % "flying-saucer-pdf-openpdf" % "9.1.12", "nu.validator.htmlparser" % "htmlparser" % "1.4", + "org.jsoup" % "jsoup" % "1.11.3" % Test, // ScalaTest + Play plugin // - http://www.scalatest.org/plus/play diff --git a/modules/play26/project/plugins.sbt b/modules/play26/project/plugins.sbt index e2cb3f5..7237dfa 100644 --- a/modules/play26/project/plugins.sbt +++ b/modules/play26/project/plugins.sbt @@ -1,5 +1,5 @@ // Play Framework plugin -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.12") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.15") // Maven publishing-specific // ~~~~~ diff --git a/modules/play26/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala b/modules/play26/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala similarity index 83% rename from modules/play26/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala rename to modules/play26/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala index 632f69b..4268db9 100644 --- a/modules/play26/test/com/builtamont/play/pdf/PdfGeneratorSpec.scala +++ b/modules/play26/test/com/hhandoko/play/pdf/PdfGeneratorSpec.scala @@ -29,11 +29,11 @@ package com.hhandoko.play.pdf import java.io.InputStream import scala.io.Source -import com.itextpdf.text.pdf.PdfReader -import com.itextpdf.text.pdf.parser.PdfTextExtractor +import com.lowagie.text.pdf.PdfReader +import com.lowagie.text.pdf.parser.PdfTextExtractor +import org.jsoup.Jsoup import org.scalatestplus.play.PlaySpec import org.scalatestplus.play.guice.GuiceOneAppPerTest - import play.api.Environment import play.twirl.api.Html @@ -46,6 +46,7 @@ class PdfGeneratorSpec extends PlaySpec with GuiceOneAppPerTest { def htmlString: String = htmlStream.fold("") { Source.fromInputStream(_).getLines().mkString("\n") } def html: Html = Html(htmlString) def gen = new PdfGenerator(env) + def clean(html: String): String = Jsoup.parse(html).text() "PdfGenerator" should { @@ -56,39 +57,43 @@ class PdfGeneratorSpec extends PlaySpec with GuiceOneAppPerTest { "be able to create PDF given HTML string" in { val pdf = gen.toBytes(htmlString, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given HTML string and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(htmlString, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML" in { val pdf = gen.toBytes(html, BASE_URL, Nil) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } "be able to create PDF given Twirl HTML and external font" in { val fonts = Seq("opensans-regular.ttf") val pdf = gen.toBytes(html, BASE_URL, fonts) val reader = new PdfReader(pdf) + val extractor = new PdfTextExtractor(reader) assert(reader.getInfo.get("Author") === author) assert(reader.getInfo.get("Title") === title) - assert(PdfTextExtractor.getTextFromPage(reader, 1).contains(heading)) + assert(clean(extractor.getTextFromPage(1)).contains(heading)) } } diff --git a/modules/play26/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala b/modules/play26/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala similarity index 100% rename from modules/play26/test/com/builtamont/play/pdf/PdfUserAgentSpec.scala rename to modules/play26/test/com/hhandoko/play/pdf/PdfUserAgentSpec.scala