Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FrameworkPDF extends PostgresqlConnection{
- /**
- * @param args
- */
- public static final String FILE = "E:/framework.pdf";
- public static final int FRAMEWORK_ID = 650;
- public static final String RESOURCE = "E:/images/logo.png";
- public static final Font BOLD_UNDERLINED = new Font(FontFamily.TIMES_ROMAN, 18,
- Font.BOLD);
- public static final Font H2 = new Font(FontFamily.TIMES_ROMAN, 14, Font.BOLD |
- Font.UNDERLINE);
- public static final Font H3 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);
- public static final Font H4 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD |
- Font.UNDERLINE);
- public static void main(String[] args)
- {
- FrameworkPDF.createPdf(FILE,
- FrameworkPDF.getFrameworkData(FRAMEWORK_ID),FRAMEWORK_ID,3);
- }
- public static void createPdf(String filename, String content, int frameworkId, int
- level) {
- Document document = new Document();
- try
- {
- PdfWriter.getInstance(document, new FileOutputStream(filename));
- document.open();
- // Adding a java.awt.Image
- java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(RESOURCE);
- Image img = com.itextpdf.text.Image.getInstance(awtImage, null);
- img.scaleToFit(120, 250);
- img.setAlignment(img.ALIGN_RIGHT);
- document.add(img);
- Paragraph p = new Paragraph();
- p.add(new Chunk(content, BOLD_UNDERLINED));
- document.add(p);
- document.add(new LineSeparator(0.5f, 100, null, 0, -5));
- Paragraph p1 = new Paragraph();
- p1.add(new Chunk("nCore Principles: ", H2));
- document.add(p1);
- int i=0;
- ArrayList<String> cp = FrameworkPDF.getRubrics(662, 3);
- Iterator<String> itr = cp.iterator();
- while(itr.hasNext())
- {
- i++;
- String s = itr.next();
- Paragraph p2 = new Paragraph();
- p2.add(new Chunk("n".concat(String.valueOf(i)).concat(".
- ").concat(s), H3));
- document.add(p2);
- }
- Paragraph p2 = new Paragraph();
- p2.add(new Chunk("nLevel wise rubrics: n", H4));
- document.add(p2);
- i=1;
- while(level > 0)
- {
- Paragraph p3 = new Paragraph();
- p3.add(new Chunk("nLevel ".concat(String.valueOf(i)), H3));
- document.add(p3);
- ArrayList<String> rub = FrameworkPDF.getRubrics(frameworkId, level);
- Iterator<String> rubitr = rub.iterator();
- while(rubitr.hasNext())
- {
- String s = rubitr.next();
- Paragraph p4 = new Paragraph();
- p4.add(new Chunk(s, H3));
- document.add(p4);
- }
- level--;
- i++;
- }
- document.add(createTable(countRatings(FRAMEWORK_ID)));
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- catch (DocumentException e)
- {
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- finally
- {
- // step 5
- document.close();
- }
- }
- }
- public class PostgresqlConnection {
- public static String sql = null;
- public static Connection conn= null;
- public static Properties props = null;
- public static String url = null;
- public static Statement stmt = null;
- public static ResultSet rs = null;
- public static void connect()
- {
- url = "jdbc:postgresql://localhost/onet";
- props = new Properties();
- props.setProperty("user","postgres");
- props.setProperty("password","password");
- try
- {
- conn = DriverManager.getConnection(url, props);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static void close()
- {
- try
- {
- if(stmt!=null)
- stmt.close();
- }
- catch(SQLException se2)
- {
- se2.printStackTrace();
- }
- try
- {
- if(rs!=null)
- rs.close();
- }
- catch(SQLException se2)
- {
- se2.printStackTrace();
- }
- try
- {
- if(conn!=null)
- conn.close();
- }
- catch(SQLException se)
- {
- se.printStackTrace();
- }
- }
- }
- FrameworkPDF.createPdf(FILE,FrameworkPDF.getFrameworkData(FRAMEWORK_ID),FRAMEWORK_ID,3);
- compile :"postgresql:postgresql:9.1-901.jdbc3"
- compile :"com.itextpdf:itext-pdfa:5.4.5"
- def dataSource
- def sql = Sql.newInstance(dataSource)
- def row = sql.firstRow("select fname, lname, email from person where id = ${personId}")
- if (row) {
- return [firstName: row.fname, lastName: row.lname, email: row.email]
- }
- beans = {
- frameworkPdfService(your.package.FrameworkPDF){}
- }
- public class MyService {
- def frameworkPdfService
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement