Hi Paulo,

I've found out that the multiplied leading doesn't work for Paragraphs 
placed into the document, is it planned to support this as in PdfPTables
or ColumnTexts?

Also I think I've discovered another bug. When you're using the spacingBefore
feature it seems it will not work for the first Paragraph, placed in the
document.

I've attached the Java source code plus a PDF for this.

Best regards,
Christian

package ujac.test.itext;

import java.io.FileOutputStream;

import com.lowagie.text.Document;

import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
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 LeadingTest {
  
  public static void main(String[] args) {
    
    try {
      FileOutputStream os = new FileOutputStream("test.pdf");
      Document document = new Document(PageSize.A4, 25, 25, 25, 25);
      PdfWriter documentWriter = PdfWriter.getInstance(document, os);
      
      document.open();
      Font font = new Font(Font.HELVETICA, 14);

      PdfPTable table = new PdfPTable(new float[] {30, 70});
      PdfPCell cell = new PdfPCell(new Phrase("Paragraphs with multiple leading in PdfPCells really works great!", font));
      table.addCell(cell);
      cell = new PdfPCell(new Phrase(0.0F));
      Paragraph paragraph = new Paragraph("Paragraph with multiple leading 1.2", font);
      paragraph.setLeading(0.0F, 1.2F);
      cell.addElement(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 2.0", font);
      paragraph.setLeading(0.0F, 2.0F);
      cell.addElement(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 3.0", font);
      paragraph.setLeading(0.0F, 3.0F);
      cell.addElement(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 4.0", font);
      paragraph.setLeading(0.0F, 4.0F);
      cell.addElement(paragraph);
      table.addCell(cell);
      document.add(table);
      
      paragraph = new Paragraph("It seems the spacingBefore measure of the first paragraph " +
          "in the document (or on a page) is not recognized, this one has spacingBefore set to 50.0.", 
          font);
      paragraph.setSpacingBefore(50.0F);
      document.add(paragraph);

      paragraph = new Paragraph("This one has a spacingBefore amount of 50.0 too!", font);
      paragraph.setSpacingBefore(50.0F);
      document.add(paragraph);

      paragraph = new Paragraph("Paragraphs with multiple leading in docment " +
          "doesn't currently seem to work ...", font);
      paragraph.setSpacingBefore(30.0F);
      paragraph.setSpacingAfter(30.0F);
      document.add(paragraph);

      paragraph = new Paragraph("Paragraph with multiple leading 1.2", font);
      paragraph.setLeading(0.0F, 1.2F);
      document.add(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 2.0", font);
      paragraph.setLeading(0.0F, 2.0F);
      document.add(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 3.0", font);
      paragraph.setLeading(0.0F, 3.0F);
      document.add(paragraph);
      paragraph = new Paragraph("Paragraph with multiple leading 4.0", font);
      paragraph.setLeading(0.0F, 4.0F);
      document.add(paragraph);
      
      document.close();
      documentWriter.close();
      
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  
}

Attachment: test.pdf
Description: Adobe PDF document

Reply via email to