Format line with itextsharp

0

How can I build a line with different formatting in itextsharp?

I tried this way:

Paragraph paragrafo = new Paragraph(Texto, new Font(Font.FontFamily.COURIER, tamanho, estilo));
doc.Add(paragrafo);

But with each "add" it plays on a new line and not the front of the previous one.

If anyone can help me, thank you.

    
asked by anonymous 19.01.2018 / 14:20

1 answer

0

Like this:

public void impF(ref StringBuilder ret, int pos, string Texto, bool pulaLinha, float fs = 7.0F, int estilo = 0)
{
    if (pulaLinha)
    {
        string x = ret + l(Texto, " ", pos - linha.Length) + "\r\n";
        ret.Clear();
        linha = "";
        Paragraph paragrafo = new Paragraph(x, new Font(Font.FontFamily.COURIER, fs, estilo));
        doc.Add(paragrafo);
    }
    else
    {
        //paragrafo.Add(l(Texto, " ", pos - linha.Length) + "\r\n");
        ret.Append(l(Texto, " ", pos - linha.Length));
        linha += l(Texto, " ", pos - linha.Length);
    }
}

In this way it mounts the line in the stringbuilder and when requested adds to the paragraph.

I would like to add each independent text to your paragraph (bold, italic, size, etc.)

It would look something like this:

public void impF(ref StringBuilder ret, int pos, string Texto, bool pulaLinha, float fs = 7.0F, int estilo = 0)
{
    Paragraph paragrafo = new Paragraph(Texto, new Font(Font.FontFamily.COURIER, fs, estilo));
    doc.Add(paragrafo);
    if (pulaLinha)
    {
        doc.Add(new Paragraph("\r\n"));
    }
}

This routine is called this:

 GeraRelatorio.impF(ref texto, 01, "Operação: " + row["cdescropera"].ToString(), true);

It works perfectly, however, the style can only be applied to the entire line.

    
19.01.2018 / 17:39