package food;


import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class Chap0607 {
    
    public static void main(String[] args) {
        
        System.out.println("Chapter 6 example 7: Scaling an Image");
        
        // step 1: creation of a document-object
        Document document = new Document();
        
        try {
            
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            
            PdfWriter.getInstance(document, new FileOutputStream("Chap0607.pdf"));
            
            // step 3: we open the document
            HeaderFooter header = new HeaderFooter(new Phrase("This is a header"), false);
            document.setHeader(header);
            document.setPageSize(PageSize.A4.rotate());
            document.setMargins(40.9f, 10.5f, 60.5f, 80f);
            Image jpg5 = Image.getInstance("C:/eclipse workspace/CorePrax/food/bfairlogonew.jpg");
            jpg5.scaleToFit(jpg5.width()-300, jpg5.height());
            Chunk ch = new Chunk(jpg5, 0, 0);
            Phrase  ph = new Phrase(ch);
            HeaderFooter  footer = new HeaderFooter(ph, false);
            document.setFooter(footer);
            document.open();
            for(int i=0;i<100;i++){
              Table aTable = new Table(4,4);
              aTable.addCell("2.2");
              aTable.addCell("3.3");
              aTable.addCell("2.1");
              aTable.addCell("1.3");
              document.add(aTable);
            }
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
        // step 5: we close the document
        document.close();
    }
}
