Advertisement
ARIELCARRARO

UsoGrapes.groovy

Jan 2nd, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.19 KB | None | 0 0
  1. /**
  2.  * @file UsoGrapes.groovy
  3.  * @version 0.0.1
  4.  * @author Ariel Carraro
  5.  * @date   02.enero.2013
  6.  * @url    codemonkey
  7.  * @description Uso de @Grapes para el uso de la librería itextpdf sin agregarla a la classpath
  8.  */
  9.  
  10. //es necesaria para usar Grapes
  11. import groovy.grape.Grape
  12. //para crear el archivo
  13. import java.io.FileOutputStream
  14. import java.io.IOException
  15.  
  16. //librería itextpdf para crear el documento PDF
  17. import com.itextpdf.text.Document
  18. import com.itextpdf.text.DocumentException
  19. import com.itextpdf.text.Paragraph
  20. import com.itextpdf.text.pdf.PdfWriter
  21.  
  22. //método principal del programa
  23. principal()
  24.  
  25.  
  26. @Grapes(@Grab(group='com.itextpdf', module='itextpdf', version='5.1.2'))
  27. def principal()throws DocumentException, IOException{
  28.     def documento="micodigo.pdf"
  29.     Document document = new Document();
  30.     PdfWriter.getInstance(document, new FileOutputStream(documento));
  31.     document.open();
  32.     document.add(new Paragraph("Usando Grapes en Groovy"));
  33.     document.add(new Paragraph("url"));
  34.     document.close();
  35.     println "Se ha creado el documento PDF"
  36. }
  37.  
  38. /*
  39. compilar:
  40. groovyc UsoGrapes.groovy
  41.  
  42. ver dependencias:
  43. grape list
  44.  
  45. ejecutar:
  46. groovy UsoGrapes.groovy
  47.  
  48. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement