/**
 * @author Jason
 * @author Brain
 * Created on March 04, 2004
 */

package org.aamc.amcas.pdf;

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class VpaLayout {
	public static void main(String[] args) {
	//	Print to screen
	System.out.println("VPA PDF File Layout Generated");
	
	Rectangle rect = new Rectangle(PageSize.A4.rotate());
	Document document = new Document(rect, 5, 5, 5, 5);
	
	try{
		FileOutputStream file = new FileOutputStream("101_2004_vpaLayout.pdf");
		PdfWriter writer = PdfWriter.getInstance(document, file);
		
		document.addTitle("VPA");
		document.addSubject("Verified Printable Application");
		document.addAuthor("AMCAS 2_0");
		document.addCreationDate();
		
		document.open();
		
		PdfPTable borderTable = new PdfPTable(1);
		borderTable.getDefaultCell().setBorder(Rectangle.BOX);
		borderTable.setWidthPercentage(100);
		
		PdfPTable headerTable = getHeaderTable(writer);
		borderTable.addCell(headerTable);
		
		if(writer.getPageNumber()>1){
			borderTable.setHeaderRows(1);
			borderTable.getHeaderRows();
		}
		
		document.add(borderTable);
		
	}
	catch(DocumentException de) {
		System.err.println(de.getMessage());
	}
	catch(IOException ioe) {
		System.err.println(ioe.getMessage());
	}			
	document.close();
	}
  
	private static PdfPTable getHeaderTable(PdfWriter writer) throws BadElementException, DocumentException, IOException{
		PdfPTable headerTable = new PdfPTable(1);
	headerTable.setWidthPercentage(100);
		//headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		
		PdfPTable titleTable = new PdfPTable(3);
	int headerTitleWidths[] = {15, 70, 15};
	titleTable.setWidths(headerTitleWidths);
	titleTable.setWidthPercentage(100);
  	
		PdfPTable dateTable = new PdfPTable(4);
	int headerDataWith[] = {25,25,25,25};
	dateTable.setWidths(headerDataWith);
	dateTable.setWidthPercentage(100);
			
		PdfPTable nameTable = new PdfPTable(4);
	int headerNameWith[] = {40,25,25,10};
	nameTable.setWidths(headerNameWith);
	nameTable.setWidthPercentage(100);
	
	Image logImg = Image.getInstance("Images/aamcrpt.bmp");
	logImg.setAlignment(Image.BOTTOM);
	
	PdfPCell imgCell = new PdfPCell(logImg);
	imgCell.setPadding(2);
	imgCell.setHorizontalAlignment(Element.ALIGN_LEFT);	
	imgCell.setVerticalAlignment(Element.ALIGN_BOTTOM);			
	imgCell.setBorder(Rectangle.NO_BORDER);
		titleTable.addCell(imgCell);
  	
		PdfPCell titleCell = new PdfPCell(new Phrase("AMCAS SUMMARY APPLICATION REPORT", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
		titleCell.setPadding(2);
		titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
		titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE);					
	titleCell.setBorder(Rectangle.NO_BORDER);
	titleTable.addCell(titleCell);		
  	
		PdfPCell pgCell = new PdfPCell(new Phrase("Regular M.D.", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	pgCell.setPadding(2);
	pgCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	imgCell.setVerticalAlignment(Element.ALIGN_TOP);						
	pgCell.setBorder(Rectangle.NO_BORDER);	
	titleTable.addCell(pgCell);
	
	Phrase repDatePhr = new Phrase();
	repDatePhr.add(new Chunk("REPORT DATE:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	repDatePhr.add(new Chunk("03/01/2004", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell repDateCell = new PdfPCell(repDatePhr);
	repDateCell.setPadding(2);
	repDateCell.setBorder(Rectangle.NO_BORDER);
	dateTable.addCell(repDateCell);
	
	
	Phrase subDatePhr = new Phrase();
	subDatePhr.add(new Chunk("SUBMISSION DATE:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	subDatePhr.add(new Chunk("07/14/2003", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell subDateCell = new PdfPCell(subDatePhr);
	subDateCell.setPadding(2);
	subDateCell.setBorder(Rectangle.NO_BORDER);
	dateTable.addCell(subDateCell);
	
	Phrase certDatePhr = new Phrase();
	certDatePhr.add(new Chunk("CERTIFICATION DATE:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	certDatePhr.add(new Chunk("06/25/2003", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell certDateCell = new PdfPCell(certDatePhr);
	certDateCell.setPadding(2);
	certDateCell.setBorder(Rectangle.NO_BORDER);
	dateTable.addCell(certDateCell);
	
	Phrase classPhr = new Phrase();
	classPhr.add(new Chunk("ENTERING DATE:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	classPhr.add(new Chunk("2004", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell classCell = new PdfPCell(classPhr);
	classCell.setPadding(2);
	classCell.setBorder(Rectangle.NO_BORDER);
	dateTable.addCell(classCell);
	
	Phrase namePhr = new Phrase();
	namePhr.add(new Chunk("Applicant's Legal Name:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	namePhr.add(new Chunk("Jason Zhaohong Gan", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell nameCell = new PdfPCell(namePhr);
	nameCell.setPadding(2);
	nameCell.setBorder(Rectangle.NO_BORDER);
	nameTable.addCell(nameCell);
	
	Phrase IDPhr = new Phrase();
	IDPhr.add(new Chunk("AAMC ID:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	IDPhr.add(new Chunk("11528154", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell IDCell = new PdfPCell(IDPhr);
	IDCell.setPadding(2);
	IDCell.setBorder(Rectangle.NO_BORDER);
	nameTable.addCell(IDCell);
	
	Phrase SSNPhr = new Phrase();
	SSNPhr.add(new Chunk("SSN:  ", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	SSNPhr.add(new Chunk("12336666", FontFactory.getFont(FontFactory.HELVETICA, 10)));
	PdfPCell SSNCell = new PdfPCell(SSNPhr);
	SSNCell.setPadding(2);
	SSNCell.setBorder(Rectangle.NO_BORDER);
	nameTable.addCell(SSNCell);
	
	Phrase PgPhr = new Phrase();
	PgPhr.add(new Chunk("Page:  " + writer.getPageNumber(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
	PdfPCell PgCell = new PdfPCell(PgPhr);
	PgCell.setPadding(2);
	PgCell.setBorder(Rectangle.NO_BORDER);
	nameTable.addCell(PgCell);
	
	
	headerTable.addCell(titleTable);
	headerTable.addCell(dateTable);
	headerTable.addCell(nameTable);
	
		return headerTable;
	}
}

