package test;

import java.awt.Dimension;
import java.awt.Insets;
import java.io.File;
import java.net.URL;

import org.zefer.pd4ml.PD4Constants;
import org.zefer.pd4ml.PD4ML;

public class EasyFonts {

	public static void main(String[] args) throws Exception {
		EasyFonts converter = new EasyFonts();
		String url = "http://lenta.ru";
		File pdfFile = new File("c:/output.pdf");
		converter.generatePDF(url, pdfFile, PD4Constants.A4);

        String params = "C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRD32.exe " + pdfFile.getAbsolutePath();
        Runtime.getRuntime().exec(params);
		
		System.out.println("done.");
	}

	private void generatePDF(String url, File outputPDFFile, Dimension format )
			throws Exception {
		
		java.io.FileOutputStream fos = new java.io.FileOutputStream(outputPDFFile);
		PD4ML pd4ml = new PD4ML();
		pd4ml.setPageInsets(new Insets(0, 0, 0, 0));
		pd4ml.setHtmlWidth(1200);
		pd4ml.setPageSize(pd4ml.changePageOrientation(format)); // landscape page orientation
		pd4ml.useTTF( "java:fonts", true );
		pd4ml.setDefaultTTFs("Times New Roman", "Arial", "Courier New");
		pd4ml.enableDebugInfo();
		
		long start = System.currentTimeMillis();
		pd4ml.render(new URL(url), fos);
		System.out.println( "done in " + (System.currentTimeMillis() - start) + "ms" );
	}
}

