I have written a code in java that help me to generate a pdf . I have used Itext libraries to generate it. This code also consists of database connectivity with postgres. I have used two jar files itextpdf-5.4.5.jar and postgresql-9.0-901.jar. But as i have mentioned that this code is in java. Now i want this code to work as service in my grails project. As i have read some documentaion of grails that grails service do not contain any database connectivity code.So kindly help me though i 'm new to grails. I don't need any plugins of grails.

**FrameworkPDF.java**

```
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();
    }
     }
    }

```

**PostgresqlConnection.java**

```
  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();
          } 
       }

       }

```