import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
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();
PdfContentByte cb = writer.getDirectContent();
String text = "this is a test";
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
cb.setFontAndSize(bf, 12);
cb.beginText();
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250, 650, 0);
cb.endText();
document.close();
}
}
|