Reputation: 97
I am missing something in the following code and I get an extra space between lines in the output
PdfContentByte ^cb = writer->DirectContent;
ColumnText ^ct = gcnew ColumnText(cb);
float gutter = 15;
float colwidth = (document->Right - document->Left - gutter) / 2;
array<float, 1>^ left = { document->Left + 133, document->Top - 35,
document->Left + 133, document->Bottom };
array<float, 1>^ right = { document->Left + colwidth, document->Top - 35,
document->Left + colwidth, document->Bottom };
for (int i = 0; i < m_strTestString->Length; i++)
{
Phrase ^Ps = gcnew Phrase(m_strTestString[i], font);
Ps->SetLeading(0.0f, 0.6f);
ct->AddText(Ps);
ct->AddText(Chunk::NEWLINE);
}
ct->SetColumns(left, right);
ct->Go();
The output is as below:
Client Name:sgsfg
Product:hjghj
Estimate#:354
I do not want the space between the above lines.
What am I doing wrong? Any help appreciated
One small clarification, if I do not add the
ct->AddText(Chunk::NEWLINE);
the output shows up as:
Client Name:sgsfgProduct:hjghjEstimate
#:354
So I do not think my issue is because of the ct->AddText(Chunk::NEWLINE);
Thanks
Upvotes: 0
Views: 506
Reputation: 95918
You should be aware that ColumnText
knows two modes of operation, text mode and composite mode.
In text mode you add stuff with AddText
and iText(Sharp) arranges the text pieces according to some ColumnText
parameters.
In composite mode you add stuff using AddElement
and iText(Sharp) arranges the elements according to the parameters they bring along.
Text mode has the advantage that it supports irregular (not necessarily rectangular) columns but essentially only supports text.
Composite mode has the advantage that it supports different kinds of elements (Paragraph
, List
, PdfPTable
, and Image
instances) but only supports rectangular columns.
In your case only text is added using only setText
calls. Thus, you are in text mode. So the text is arranged according to ColumnText
parameters. As you meanwhile (while I wrote my answer) have discovered yourself, you therefore have to use
ct->SetLeading(0.0f, 0.6f);
instead of
Ps->SetLeading(0.0f, 0.6f);
Upvotes: 2
Reputation: 97
I figured it out
Instead of
Ps->SetLeading(0.0f, 0.6f);
I need to do
ct->SetLeading(0.0f, 0.6f);
Upvotes: 0