import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;
public class UsingBaseFontPDF {
public static void main(String[] args) {
try {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("UsingBaseFontPDF.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
document.newPage();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 14);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "www.java2java.com", 100 / 2, 40, 0);
cb.endText();
document.close();
} catch (Exception de) {
de.printStackTrace();
}
}
}
|