Monday, November 29, 2004

Use iText to create pdf file

package uhn;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import java.io.*;
import java.awt.Color;

/**
*
* @author zlu
*/
public class Test {

/** Creates a new instance of Test */
public Test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("\\temp\\Chap0101.pdf"));
document.addTitle("This is a test for iText.");
document.addAuthor("Zhibin Lu");
document.open();
document.add(new Paragraph("Hello World"));
Chunk chunk = new Chunk("Hello world", FontFactory.getFont(FontFactory.TIMES_ROMAN, 20, Font.NORMAL, new Color(255, 0, 0)));
chunk.setBackground(new Color(0xFF, 0xFF, 0x00));
document.add(chunk);
chunk = new Chunk("This is a test for no format text.");
document.add(chunk);
document.close();
}

}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home