import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
PdfPCell cell = new PdfPCell(new Paragraph(
"Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog."));
Phrase p = new Phrase("Quick brown fox jumps over the lazy dog");
table.getDefaultCell().setPadding(2);
table.getDefaultCell().setUseAscender(false);
table.getDefaultCell().setUseDescender(false);
table.addCell("padding 2; no ascender, no descender");
table.addCell(p);
table.getDefaultCell().setUseAscender(true);
table.getDefaultCell().setUseDescender(false);
table.addCell("padding 2; ascender, no descender");
table.addCell(p);
table.getDefaultCell().setUseAscender(false);
table.getDefaultCell().setUseDescender(true);
table.addCell("padding 2; descender, no ascender");
table.addCell(p);
table.getDefaultCell().setUseAscender(true);
table.getDefaultCell().setUseDescender(true);
table.addCell("padding 2; ascender and descender");
cell.setPadding(2);
cell.setUseAscender(true);
cell.setUseDescender(true);
table.addCell(p);
document.add(table);
document.close();
}
}
|