Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Set leading for table cell

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."));     table.addCell("default leading / spacing");     table.addCell(cell);     table.addCell("absolute leading: 20");     cell.setLeading(20f, 0f);     table.addCell(cell);     table.addCell("absolute leading: 3; relative leading: 1.2");     cell.setLeading(3f, 1.2f);     table.addCell(cell);     table.addCell("absolute leading: 0; relative leading: 1.2");     cell.setLeading(0f, 1.2f);     table.addCell(cell);     table.addCell("no leading at all");     cell.setLeading(0f, 0f);     table.addCell(cell);     document.add(table);     document.close();   } }