Well, it looks like you stumbled upon the difference between text mode and composite mode:
- text mode => call
ColumnText.AddText() using the built-in Chunk and Phrase objects. - composite mode => call
ColumnText.AddText() using container objects such as paragraph, image, etc.
When you are in text mode, you add a space between paragraphs by setting the ColumnText property.
When you are in difficult mode, you add space between the objects of the "container", as usual, for example, as if you were not using ColumnText .
Here is an example showing the difference between the two modes:
int status = 0; string paragraph ="iText ยฎ is a library that allows you to create and manipulate PDF documents. It enables developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation."; using (Document document = new Document()) { PdfWriter writer = PdfWriter.GetInstance(document, STREAM); document.Open(); ColumnText ct = new ColumnText(writer.DirectContent); ct.SetSimpleColumn(36, 36, 400, 792); /* * "composite mode"; use AddElement() with "container" objects * like Paragraph, Image, etc */ for (int i = 0; i < 4; ++i) { Paragraph p = new Paragraph(paragraph); // space between paragraphs p.SpacingAfter = 0; ct.AddElement(p); status = ct.Go(); } /* * "text mode"; use AddText() with the "inline" Chunk and Phrase objects */ document.NewPage(); status = 0; ct = new ColumnText(writer.DirectContent); for (int i = 0; i < 4; ++i) { ct.AddText(new Phrase(paragraph)); // Chunk and Phrase are "inline"; explicitly add newline/break ct.AddText(Chunk.NEWLINE); } // set space between "paragraphs" on the ColumnText object! ct.ExtraParagraphSpace = 6; while (ColumnText.HasMoreText(status)) { ct.SetSimpleColumn(36, 36, 400, 792); status = ct.Go(); } }
So, now that you have updated your code and use composite mode with AddElement() , p.SpacingAfter = 0 WILL , remove the spacing between paragraphs. Or install it the way you want, instead of Paragraph.Leading .
source share