import java.awt.Color;
import java.io.*;

import com.lowagie.text.*;
import com.lowagie.text.html.*;

public class testInsertionHTML {
    
    public static void main(String[] args) {
        // creation of the document with a certain size and certain margins
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        Chapter chapitre = null;
        try {
		HtmlWriter writer = HtmlWriter.getInstance(document, new FileOutputStream("testInsertionHTML.html"));
		document.open();

        	Paragraph tmp_p = new Paragraph(new Chunk(" ",new Font(Font.COURIER,1,Font.NORMAL, new Color(255,255,255))));
  		tmp_p.setLeading(0); 
  		chapitre = new Chapter(tmp_p,1);
        	chapitre.setNumberDepth(0);
        	     		
		BufferedReader buff = new BufferedReader(new FileReader("main.html"));
		
		String tmp = buff.readLine();
		int i = 1;
		while ((tmp.indexOf("<BODY") == -1) && (tmp.indexOf("<body") == -1)){
			System.err.println("main.htm -> ligne "+i+" : "+tmp);
			tmp = buff.readLine();
			i++;
		}
		int indexBody = 0;
		if (tmp.indexOf("<BODY") > -1 || tmp.indexOf("<body") > -1){
			indexBody = tmp.indexOf(">");
		}	
		tmp = tmp.substring(indexBody+1);
		chapitre.add(new Phrase(tmp));
		
		while ((tmp.indexOf("</BODY") == -1) && (tmp.indexOf("</body") == -1)){
			System.err.println("main.htm <- ligne "+i+" : "+tmp);
			chapitre.add(new Phrase(tmp));
			tmp = buff.readLine();
			i++;
		}
		
		if (tmp.indexOf("</BODY>") > -1){
			indexBody = tmp.indexOf("</BODY>");
		}
		else if (tmp.indexOf("</body>") > -1){
			indexBody = tmp.indexOf("</body>");
		}	
		tmp = tmp.substring(0, indexBody);
		buff.close();
		document.add(chapitre);
		document.close();
        }
        catch(Exception e) {
        	e.printStackTrace();
        }
    }
    
}

