Class to write / read TXT files with formatting [closed]

0

I am using% w / o TextWriter to read / write a card voucher as a Classe but it does not have the property for letter size, spacing, etc. formatting. This makes the voucher printed on the thermal printer go out without symmetry.

My question is, is there another Class in C # that does this, but with the formatting options?

public void LerConfirmacao()
    {
        if (File.Exists(ConfigurationManager.AppSettings["Comprovante"]))
        {
            File.Create(ConfigurationManager.AppSettings["Comprovante"]).Close();
        }

        TextWriter textWriter = File.AppendText(ConfigurationManager.AppSettings["Comprovante"]);
        string[] linhas = File.ReadAllLines(ConfigurationManager.AppSettings["001Resp"]);
        foreach (string linha in linhas)
        {
            if (linha.Substring(0, 3) == "029")
            {
                textWriter.WriteLine(linha.Substring(10));
            }
        }

        textWriter.Close();

        if (Directory.Exists(ConfigurationManager.AppSettings["Pagamentos"]))
        {
            Directory.CreateDirectory(ConfigurationManager.AppSettings["Pagamentos"]);
        }
        Directory.CreateDirectory(ConfigurationManager.AppSettings["Pagamentos"]);
        //File.Create(ConfigurationManager.AppSettings["Pagamentos"]).Close();
        string nomeArquivo = ConfigurationManager.AppSettings["Pagamentos"] + "Comprovante_" + PedNumero + "_" + PedFrmPgto;
        TextWriter writer = File.AppendText(nomeArquivo);

        foreach (string item in File.ReadAllLines(ConfigurationManager.AppSettings["Comprovante"]))
        {
            writer.WriteLine(item);
        }
        writer.Close();
    }
    
asked by anonymous 01.02.2018 / 14:27

1 answer

1

.txt files have no formatting. You should use another extension (Example: .rtf). What you can do is to use RichTextBox to format the text. Example:

RichTextBox formatar = new RichTextBox();
formatar.Text = "texto1 ABC";
formatar.Select(2,4);
formatar.SelectionBackColor = Color.Red;
formatar.SaveFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/teste.rtf");
    
01.02.2018 / 15:55