Performance ItextSharp

3

I am doing the reports using iTextsharp and the result has been acceptable, however when working with many records it has become slow. Currently I do this:

I get the bank data (storing in DataTable );

In a foreach concatenate everything in a string : (ex rough)

foreach (DataRow row in FaturamentoCorpo.Rows)
  stringao += row["ncodigfilia"].ToString()

In the final game for iTextsharp this "string":

Paragraph paragrafo = new Paragraph("", new Font(Font.FontFamily.COURIER, FontSize));
paragrafo.Add(stringao);

Then this loop concatenating in string , when DataTable has ai + - 10k records, resulting in a PDF of 70 to 80 pages, it is rather time-consuming.

So I wanted a better way to work this out?

    
asked by anonymous 16.12.2017 / 14:32

1 answer

2

I answered the problem in another answer ( other ).

You can not do it because the more you concatenate, the slower it gets, and it's exponential, it quickly gets tragic. So I would have to do something like this:

var todasLinhas = new StringBuilder();
foreach (DataRow row in FaturamentoCorpo.Rows)
    todasLinhas += row["ncodigfilia"].ToString();
var paragrafo = todasLinhas.ToString();

I placed GitHub for future reference.

Ideally it would be nice to try to figure out at least the approximate total size this string will have and instantiate StringBuilder with that size. It seems to be possible since you know how many rows you have and imagine you have to know, if not exact, at least approximate the size of each line.

One more explanation .

Searching links I'm starting to find duplicate .

    
16.12.2017 / 15:40