Jahanzaib Niazi
Jahanzaib Niazi

Reputation: 3

Remove line gapping in PDF

I have used following code given below to print a line of text in pdf using itextsharp library. But line gap is more as shown in image here

here is image

PdfContentByte cb1 = writer.DirectContent;
ColumnText ct = new ColumnText(cb1);
ct.SetSimpleColumn(
    new Phrase(new Chunk(text, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 09, Font.BOLD))),
    46, 270, 550, 36, 25, Element.ALIGN_LEFT | Element.ALIGN_TOP);
ct.Go();

Upvotes: 0

Views: 101

Answers (1)

mkl
mkl

Reputation: 95918

This large gap is exactly what you ask for!

Consider

ct.SetSimpleColumn(
    new Phrase(new Chunk(text, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 09, Font.BOLD))),
    46, 270, 550, 36, 25, Element.ALIGN_LEFT | Element.ALIGN_TOP);

The parameters of SetSimpleColumn are specified as

/**
 * Simplified method for rectangular columns.
 * @param phrase a <CODE>Phrase</CODE>
 * @param llx the lower left x corner
 * @param lly the lower left y corner
 * @param urx the upper right x corner
 * @param ury the upper right y corner
 * @param leading the leading
 * @param alignment the column alignment
 */
virtual public void SetSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment)

Leading in PDFs is defined as

9.3.5 Leading

The leading parameter, Tl, shall be specified in unscaled text space units. It specifies the vertical distance between the baselines of adjacent lines of text, as shown in Figure 44.

Leading

(ISO 32000-1)

In your case you have 9-point text with a 25-point leading and, therefore, huge gaps. If you want smaller gaps, choose a smaller leading here.

Upvotes: 1

Related Questions