For some next test, I want to create a PDF
(later with data of the database)
It´s the first time, I combine a Java-Lib with groovy.
It seems, that iText is state of the the art for producing PDFs.
http://itextpdf.com/
I found only few combination at google: Groovy and iText.
This link lead to empty pages (but the contents looked good)
http://swik.net/technology/dzone.com:+tech+links/Generate+a+PDF+book+with+groovy+and+iText/by7jg
This one was a great help.
http://milkedeek.wordpress.com/2012/01/03/itext-on-the-jvm/
Before the information is lost, I copy it to here.
It was very easy, strait forward. Copy th download of iText to groovy/lib
and the imports will the solved. Some magic with Java for the newbee,
but it realy works.
goovy pdf.groovy and the PDF-File is created
As you can see, the code is straightforward and simple and it looks pretty much like Jython. I prefer Groovy over Jython because it’s much faster and actually feels like a JVM language and not like a port of another language. Still a lot of love for Python though.
(later with data of the database)
It´s the first time, I combine a Java-Lib with groovy.
It seems, that iText is state of the the art for producing PDFs.
http://itextpdf.com/
I found only few combination at google: Groovy and iText.
This link lead to empty pages (but the contents looked good)
http://swik.net/technology/dzone.com:+tech+links/Generate+a+PDF+book+with+groovy+and+iText/by7jg
This one was a great help.
http://milkedeek.wordpress.com/2012/01/03/itext-on-the-jvm/
Before the information is lost, I copy it to here.
It was very easy, strait forward. Copy th download of iText to groovy/lib
and the imports will the solved. Some magic with Java for the newbee,
but it realy works.
goovy pdf.groovy and the PDF-File is created
Groovy
I followed some Groovy talks during Devoxx 2011 and I was impressed by the language, but I haven’t been able to test it out, up until now. As with Jython, it was pretty easy to install and to import iText into a project. It’s actually the same process as you would import a jar into a Java project. Assuming that you’re able to do that without instructions, so here’s the Hello World code for Groovy:01 | /* |
02 | * Created on 28-dec.-2011 |
03 | * Creating a simple Hello World pdf in Groovy using iText 5.1.3 |
04 | * @author: iText |
05 | */ |
06 | import com.itextpdf.text.Document |
07 | import com.itextpdf.text.Paragraph |
08 | import com.itextpdf.text.pdf.PdfWriter |
09 |
10 | // step 1 |
11 | def document = new Document() |
12 | println( "Document Created" ) |
13 |
14 | // step 2 |
15 | PdfWriter.getInstance(document, new FileOutputStream( "document.pdf" )) |
16 | println( "PdfWriter Created" ) |
17 |
18 | // step 3 |
19 | document.open() |
20 | println( "Document Opened" ) |
21 |
22 | // step 4 |
23 | document.add( new Paragraph( "Hello Groovy!" )) |
24 | println( "Content Added" ) |
25 |
26 | // step 5 |
27 | document.close() |
28 | println( "Document Closed" ) |
As you can see, the code is straightforward and simple and it looks pretty much like Jython. I prefer Groovy over Jython because it’s much faster and actually feels like a JVM language and not like a port of another language. Still a lot of love for Python though.