I've found out that in case a indention is defined for a chapter with
sub-sections and the contents of the whole chapter spans over more than
one page, the indention differs from page to page. Is this a bug in
iText, or am I doing something wrong?

I've attached the source code of an example, showing this effect and the
according PDF.

Best regards,
Christian

Attachment: sectionTest.pdf
Description: Adobe PDF document

package ujac.test.itext;

import java.io.FileOutputStream;

import com.lowagie.text.Document;

import com.lowagie.text.Chapter;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Section;

import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class SectionTest {
  
  public static void main(String[] args) {
    
    try {
      FileOutputStream os = new FileOutputStream("sectionTest.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);
      Paragraph title = new Paragraph("Chapter", font);
      Chapter chapter = new Chapter(title, 1);
      chapter.setIndentation(10);
      
      chapter.add(new Paragraph("Chapter contents"));

      for (int i = 0; i < 50; i++) {
        title = new Paragraph("Section", font);
        Section section = chapter.addSection(title, 2);
        section.setIndentation(10);
        section.add(new Paragraph("Section contents"));
      }
      
      document.add(chapter);

      document.close();
      documentWriter.close();
      
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  
}

Reply via email to