import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;
//import java.util.*;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.security.*;

public class tennant_test {
    
    public static void main(String[] args) {
        try {
            Document document = new Document();
            PdfPCell cell = null;
            
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\\tennant_test.pdf"));
            
            //PdfWriter.getInstance(document, new FileOutputStream("\\data\\pdf\\test1.pdf"));
            
            // Extra stuff to add META DATA
            document.addTitle("Notice to Vacate #1063");
            document.addSubject("Notice to Vacate");
            document.addCreator("VCAT");
            document.addAuthor("Loatier Pty Ltd");
            
            // Try ARIAL registration !
            FontFactory.registerDirectories();
            
            
            // set the fonts
            Font prt1 = FontFactory.getFont("Arial", 28, Font.BOLD);
            Font prt2 = FontFactory.getFont("Arial", 16, Font.BOLD);
            Font prt3 = FontFactory.getFont("Arial", 8, Font.NORMAL);
            Font prt4 = FontFactory.getFont("Arial", 10, Font.BOLD);
            Font prt5 = FontFactory.getFont("Arial", 10, Font.NORMAL);
            Font prt6 = FontFactory.getFont("Arial", 12, Font.BOLD);
            Font prt7 = FontFactory.getFont("Arial", 10, Font.BOLD | Font.UNDERLINE);
            
/*
Font prt1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 28, Font.BOLD);
Font prt2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD);
Font prt3 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, Font.NORMAL);
Font prt4 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.BOLD);
Font prt5 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
Font prt6 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
 */
            
            // step 3: we open the document
            document.open();
            
            // HEADER AREA
            PdfPTable mainTab = new PdfPTable(2);		// 2 cols, 2 rows
            float[] widths = {1, 1};
            float[] widths2 = {5, 95};
            mainTab.setWidthPercentage(100);
            mainTab.setWidths(widths);
            //mainTab.setBorder(Rectangle.NO_BORDER);
            //mainTab.setPadding(1);
            
            Phrase ntv = new Phrase("Notice to Vacate", prt1);
            Phrase toTenant = new Phrase("To tenant of rented premises", prt2);
            Phrase rta = new Phrase("Residential Tenancies Act 1997 S319 Regulation 8", prt3);
            
            cell = new PdfPCell(ntv);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setBorder(Rectangle.NO_BORDER);
            mainTab.addCell(cell);
            
            cell = new PdfPCell(toTenant);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
            mainTab.addCell(cell);
            
            cell = new PdfPCell(rta);
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setColspan(2);
            mainTab.addCell(cell);
            
            document.add(mainTab);
            document.add(new Paragraph(2, " "));
            
            Graphic grx = new Graphic();
            grx.setHorizontalLine(1, 100);
            document.add(grx);
            
            // DATA AREA
            mainTab = new PdfPTable(2);		// 2 cols, 1 row
            mainTab.setWidthPercentage(100);
            mainTab.setWidths(widths);
            //mainTab.setBorder(Rectangle.NO_BORDER);
            //mainTab.setPadding(1);
            
            
            // LEFT HAND COLUMN
            cell = new PdfPCell(new Phrase("Tenant Details\n", prt6));
            cell.setBorder(Rectangle.NO_BORDER);
            //cell.setLeading(12);
            
            cell.addElement(new Paragraph(" "));
            List sectionHead = new List(true, 14);
            sectionHead.add(new ListItem("This notice is given to", prt4));
            cell.addElement(sectionHead);
            
            
            List sectionData = new List(false, 11);
            sectionData.setListSymbol(new Chunk(" "));
            ListItem listItem = new ListItem("Ying Deng", prt5);
            sectionData.add(listItem);
            
            listItem = new ListItem("Snuggle Puss", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            // 2. REGARDING THE RENTED PREMISES AT
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(2);
            sectionHead.add(new ListItem("Regarding the rented premises at", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("54 Smith Street", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("Collingwood", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("VIC 3066", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            
            // 3. TENANT/S ADDRESS
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(3);
            sectionHead.add(new ListItem("Tenant/s address", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("54 Smith Street", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("Collingwood", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("VIC 3066", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            // LANDLORD DETAILS
            cell.addElement(new Paragraph(new Phrase("\n\nLandlord Details", prt6)));
            
            // I AM GIVING YOU THIS NOTICE AS THE LANDLORD
            sectionHead = new List(true, 14);
            sectionHead.setFirst(4);
            sectionHead.add(new ListItem("I am giving you this notice as the landlord", prt4));
            cell.addElement(sectionHead);
            
            // 5. LANDLORDs NAME
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(5);
            sectionHead.add(new ListItem("Landlord's name", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("Black Horse Estate Agency (ACN 123456789)", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            
            // 6. ADDRESS FOR SERVING DOCUMENTS
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(6);
            sectionHead.add(new ListItem("Address for serving documents", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("Level 6", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("580 Glenferrie Road", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("Under the second tree on the left", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("MALVERN", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("VIC 3144", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            
            // 7. CONTACT TELEPHONE NUMBERS ARE
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(7);
            sectionHead.add(new ListItem("Contact telephone numbers are", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("9878 4545\t\t(B/H)", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("9545 4545\t\t(A/H)", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            // TERMINATION DATE
            cell.addElement(new Paragraph(new Phrase("\n\nTermination Date", prt6)));
            sectionHead = new List(true, 14);
            sectionHead.setFirst(8);
            sectionHead.add(new ListItem("The Residential Tenancies Act 1997 requires me to give you at least 60 days' notice to vacate.", prt5));
            cell.addElement(sectionHead);
            
            cell.addElement(new Paragraph("\n "));
            sectionData = new List(false, 14);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("I require you to vacate on or before", prt5);
            sectionData.add(listItem);
            listItem = new ListItem("20 October 2004", prt7);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            mainTab.addCell(cell);
            
            // RIGHT HAND SIDE
            // 9 REASON FOR NOTICE TO VACATE
            sectionHead = new List(true, 17);
            sectionHead.setFirst(9);
            sectionHead.add(new ListItem("Reason for Notice to Vacate", prt4));
            cell = new PdfPCell((Phrase)null);
            cell.addElement(sectionHead);
            cell.setBorder(Rectangle.NO_BORDER);
            //cell.setLeading(12);
            
            //cell.addElement(new Paragraph("\n "));
            sectionData = new List(false, 17);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("\nSection 258(1)", prt5);
            sectionData.add(listItem);
            
            // LEADING DOESNT WORK IF THIS IS PLACED IN A CELL, IT USES THE CELL LEADING.
            // COULD CREATE AN EMBEDDED TABLE WITH NEW CELL LEADING BUT THEN HOW TO POSITION TABLE INDENTED LIKE
            // A LIST ITEM?
            listItem = new ListItem(11,"\nThe premises are to be occupied by me, my partner, son, daughter, parent, partner's parent, or a person who normally lives with and is dependent on me immediately after the termination date.", prt5);
            sectionData.add(listItem);
            
            cell.addElement(sectionData);
            
            // 10. THIS NOTICE IS GIVEN BY
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 17);
            sectionHead.setFirst(10);
            sectionHead.add(new ListItem("This notice is given by", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 17);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("Registered Post on 18 August 2004", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            
            // 11. SIGNATURE OF LANDLORD
            cell.addElement(new Paragraph("\n"));
            sectionHead = new List(true, 17);
            sectionHead.setFirst(11);
            ListItem li = new ListItem("Signature of Landlord", prt4);
            li.setSpacingAfter(5);
            sectionHead.add(li);
            cell.addElement(sectionHead);
            
            PdfPTable sigBox = new PdfPTable(1);
            sigBox.setWidthPercentage(85);
            sigBox.setHorizontalAlignment(Element.ALIGN_RIGHT);
            sigBox.getDefaultCell().setFixedHeight(30);
            sigBox.addCell("");
            cell.addElement(sigBox);
            
            
            // 12. NAME OF LANDLORD...
            sectionHead = new List(true, 17);
            sectionHead.setFirst(12);
            sectionHead.add(new ListItem("Name of landlord signing this notice", prt4));
            cell.addElement(sectionHead);
            
            sectionData = new List(false, 17);
            sectionData.setListSymbol(new Chunk(" "));
            listItem = new ListItem("Fred Frog", prt5);
            sectionData.add(listItem);
            cell.addElement(sectionData);
            
            mainTab.addCell(cell);
            
            document.add(mainTab);
            
            //Phrase frog = new Phrase(11,"\nThe premises are to be occupied by me, my partner, son, daughter, parent, partner's parent, or a person who normally lives with and is dependent on me immediately after the termination date.", prt5);
            //document.add(frog);
            
            // step 5: we close the document
            document.close();
            System.out.println("Fim.");
        }
        catch (Exception e) {
            e.printStackTrace(System.out);
        }
    }
}
