Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. public class FrameworkPDF extends PostgresqlConnection{
  2.  
  3. /**
  4. * @param args
  5. */
  6. public static final String FILE = "E:/framework.pdf";
  7. public static final int FRAMEWORK_ID = 650;
  8. public static final String RESOURCE = "E:/images/logo.png";
  9. public static final Font BOLD_UNDERLINED = new Font(FontFamily.TIMES_ROMAN, 18,
  10. Font.BOLD);
  11. public static final Font H2 = new Font(FontFamily.TIMES_ROMAN, 14, Font.BOLD |
  12. Font.UNDERLINE);
  13. public static final Font H3 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);
  14. public static final Font H4 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD |
  15. Font.UNDERLINE);
  16.  
  17. public static void main(String[] args)
  18. {
  19.  
  20. FrameworkPDF.createPdf(FILE,
  21. FrameworkPDF.getFrameworkData(FRAMEWORK_ID),FRAMEWORK_ID,3);
  22.  
  23. }
  24.  
  25.  
  26. public static void createPdf(String filename, String content, int frameworkId, int
  27. level) {
  28. Document document = new Document();
  29. try
  30. {
  31. PdfWriter.getInstance(document, new FileOutputStream(filename));
  32.  
  33. document.open();
  34.  
  35.  
  36. // Adding a java.awt.Image
  37. java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(RESOURCE);
  38. Image img = com.itextpdf.text.Image.getInstance(awtImage, null);
  39. img.scaleToFit(120, 250);
  40. img.setAlignment(img.ALIGN_RIGHT);
  41. document.add(img);
  42.  
  43. Paragraph p = new Paragraph();
  44. p.add(new Chunk(content, BOLD_UNDERLINED));
  45. document.add(p);
  46.  
  47. document.add(new LineSeparator(0.5f, 100, null, 0, -5));
  48.  
  49. Paragraph p1 = new Paragraph();
  50. p1.add(new Chunk("nCore Principles: ", H2));
  51. document.add(p1);
  52.  
  53. int i=0;
  54.  
  55. ArrayList<String> cp = FrameworkPDF.getRubrics(662, 3);
  56. Iterator<String> itr = cp.iterator();
  57. while(itr.hasNext())
  58. {
  59. i++;
  60.  
  61. String s = itr.next();
  62.  
  63. Paragraph p2 = new Paragraph();
  64. p2.add(new Chunk("n".concat(String.valueOf(i)).concat(".
  65. ").concat(s), H3));
  66. document.add(p2);
  67. }
  68.  
  69. Paragraph p2 = new Paragraph();
  70. p2.add(new Chunk("nLevel wise rubrics: n", H4));
  71. document.add(p2);
  72.  
  73. i=1;
  74.  
  75. while(level > 0)
  76. {
  77.  
  78. Paragraph p3 = new Paragraph();
  79. p3.add(new Chunk("nLevel ".concat(String.valueOf(i)), H3));
  80. document.add(p3);
  81.  
  82. ArrayList<String> rub = FrameworkPDF.getRubrics(frameworkId, level);
  83. Iterator<String> rubitr = rub.iterator();
  84. while(rubitr.hasNext())
  85. {
  86. String s = rubitr.next();
  87.  
  88. Paragraph p4 = new Paragraph();
  89. p4.add(new Chunk(s, H3));
  90. document.add(p4);
  91. }
  92.  
  93.  
  94. level--;
  95. i++;
  96. }
  97.  
  98. document.add(createTable(countRatings(FRAMEWORK_ID)));
  99.  
  100.  
  101. }
  102. catch (FileNotFoundException e)
  103. {
  104. e.printStackTrace();
  105. }
  106. catch (DocumentException e)
  107. {
  108. e.printStackTrace();
  109. } catch (IOException e) {
  110. // TODO Auto-generated catch block
  111. e.printStackTrace();
  112. }
  113. finally
  114. {
  115. // step 5
  116. document.close();
  117. }
  118. }
  119. }
  120.  
  121. public class PostgresqlConnection {
  122.  
  123. public static String sql = null;
  124. public static Connection conn= null;
  125. public static Properties props = null;
  126. public static String url = null;
  127. public static Statement stmt = null;
  128. public static ResultSet rs = null;
  129.  
  130. public static void connect()
  131. {
  132. url = "jdbc:postgresql://localhost/onet";
  133. props = new Properties();
  134. props.setProperty("user","postgres");
  135. props.setProperty("password","password");
  136. try
  137. {
  138. conn = DriverManager.getConnection(url, props);
  139. }
  140. catch (SQLException e)
  141. {
  142. e.printStackTrace();
  143. }
  144. }
  145.  
  146. public static void close()
  147. {
  148.  
  149. try
  150. {
  151. if(stmt!=null)
  152. stmt.close();
  153. }
  154. catch(SQLException se2)
  155. {
  156. se2.printStackTrace();
  157. }
  158.  
  159. try
  160. {
  161. if(rs!=null)
  162. rs.close();
  163. }
  164. catch(SQLException se2)
  165. {
  166. se2.printStackTrace();
  167. }
  168.  
  169. try
  170. {
  171. if(conn!=null)
  172. conn.close();
  173. }
  174. catch(SQLException se)
  175. {
  176. se.printStackTrace();
  177. }
  178. }
  179.  
  180. }
  181.  
  182. FrameworkPDF.createPdf(FILE,FrameworkPDF.getFrameworkData(FRAMEWORK_ID),FRAMEWORK_ID,3);
  183.  
  184. compile :"postgresql:postgresql:9.1-901.jdbc3"
  185. compile :"com.itextpdf:itext-pdfa:5.4.5"
  186.  
  187. def dataSource
  188. def sql = Sql.newInstance(dataSource)
  189. def row = sql.firstRow("select fname, lname, email from person where id = ${personId}")
  190. if (row) {
  191. return [firstName: row.fname, lastName: row.lname, email: row.email]
  192. }
  193.  
  194. beans = {
  195. frameworkPdfService(your.package.FrameworkPDF){}
  196. }
  197.  
  198. public class MyService {
  199. def frameworkPdfService
  200. ...
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement