import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfTextArray;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(
document,
new FileOutputStream("2.pdf"));
document.open();
String text = "java2s";
PdfContentByte cb = writer.getDirectContent();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
cb.beginText();
PdfTemplate tp1 = cb.createTemplate(160, 36);
tp1.beginText();
tp1.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
tp1.setFontAndSize(bf, 24);
tp1.moveText(6, -6);
tp1.showText(text);
tp1.endText();
cb.addTemplate(tp1, 36, 240);
cb.endText();
document.close();
}
}
|