package main_package;

import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPages;
import com.itextpdf.text.pdf.PdfWriter;

public class Test1 {

	public static void main(String[] args) throws Exception 
	{
		/*Document document=new Document(PageSize.A4);
		PdfWriter.getInstance(document,new FileOutputStream("D:\\TestTable.pdf"));
		document.open();
		PdfPTable table=new PdfPTable(20);
		table.addCell("Share Holder");
		table.addCell("Loan Type");
		try(Connection con=DataBaseConnection.JAVAConnection();) 
		{
			Statement st= con.createStatement();
			ResultSet rs= st.executeQuery("Select * from debit_loan"); // data is the table name here
			while(rs.next())
			{
				table.addCell(rs.getString("shareholderno"));
				table.addCell(rs.getString("loanType"));
				table.addCell(rs.getString("loanNo"));
				document.add(table);
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		
		document.close();*/
		//createSamplePDF(new String[]{"col1", "col2"}, new String[][]{{"rw11", "rw12"},{"rw21", "rw22"}});
		String plno="PL-00001";
		String str[]=plno.split("/");
		System.out.println(str[1]);
	}	
	
	public static void createSamplePDF(String header[], String body[][]) throws Exception{
	    Document documento = new Document();
	    //Create new File
	    File file = new File("D:/newFileName.pdf");
	    file.createNewFile();
	    FileOutputStream fop = new FileOutputStream(file);
	    PdfWriter.getInstance(documento, fop);
	    documento.open(); 
	    //Fonts
	    Font fontHeader = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
	    Font fontBody = new Font(Font.FontFamily.COURIER, 12, Font.NORMAL);
	    //Table for header
	    PdfPTable cabetabla = new PdfPTable(header.length);
	    for (int j = 0; j < header.length; j++) {
	        Phrase frase = new Phrase(header[j], fontHeader);
	        PdfPCell cell = new PdfPCell(frase);
	        cell.setBackgroundColor(new BaseColor(Color.lightGray.getRGB()));
	        cabetabla.addCell(cell);
	    }
	    documento.add(cabetabla);
	    //Tabla for body
	    PdfPTable tabla = new PdfPTable(header.length);
	    for (int i = 0; i < body.length; i++) {
	        for (int j = 0; j < body[i].length; j++) {
	            tabla.addCell(new Phrase(body[i][j], fontBody));
	        }
	    }
	    documento.add(tabla);
	    documento.close();
	    fop.flush();
	    fop.close();
	}

}


//createSamplePDF(new String[]{"col1", "col2"}, new String[][]{{"rw11", "rw12"},{"rw21", "rw22"}});

