Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
Please help me i am amateur programmer.
I have made an app that i can browse txt files with Greek characters inside and i can send it to thermal printer directly with ip.
My problem is the Greek characters printing something like symbols

What I have tried:

C#
namespace SendFiles
{
    public partial class Form1 : Form
    {
        public string SendingFilePath = string.Empty;
        private const int BufferSize = 1024;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            progressBar1.Visible=true;
            progressBar1.Minimum=1;
            progressBar1.Value=1;
            progressBar1.Step=1;
            
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog Dlg = new OpenFileDialog();
            Dlg.Filter = "All Files (*.*)|*.*";
            Dlg.CheckFileExists = true;
            Dlg.Title = "Choose a File";
            Dlg.InitialDirectory = @"C:\";
            if (Dlg.ShowDialog() == DialogResult.OK)
            {
                SendingFilePath = Dlg.FileName;
                
            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if (SendingFilePath != string.Empty)
            {   
                SendTCP(SendingFilePath, txtIP.Text, Int32.Parse(txtPort.Text));
            }
            else
                MessageBox.Show("Select a file","Warning");
        }
        public void SendTCP(string M, string IPA, Int32 PortN)
        {
            byte[] SendingBuffer = null;
            TcpClient client = null;
            lblStatus.Text = "";
            NetworkStream netstream = null;
            try
            {
                client = new TcpClient(IPA, PortN);
                lblStatus.Text = "Connected to the Server...\n";
                netstream = client.GetStream();
                FileStream Fs = new FileStream(M, FileMode.Open, FileAccess.Read);
                int NoOfPackets = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Fs.Length) / Convert.ToDouble(BufferSize)));
                progressBar1.Maximum = NoOfPackets;
                int TotalLength = (int)Fs.Length, CurrentPacketLength, counter = 0;
                for (int i = 0; i < NoOfPackets; i++)
                {
                    if (TotalLength > BufferSize)
                    {
                        CurrentPacketLength = BufferSize;
                        TotalLength = TotalLength - CurrentPacketLength;
                    }
                    else
                        CurrentPacketLength = TotalLength;
                    SendingBuffer = new byte[CurrentPacketLength];
                    Fs.Read(SendingBuffer, 0, CurrentPacketLength);
                    netstream.Write(SendingBuffer, 0, (int)SendingBuffer.Length);
                    if (progressBar1.Value >= progressBar1.Maximum)
                        progressBar1.Value = progressBar1.Minimum;
                    progressBar1.PerformStep();
                }
                
                lblStatus.Text=lblStatus.Text+"Sent "+Fs.Length.ToString()+" bytes to the server";
                Fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                netstream.Close();
                client.Close();

            }
        }
        
      
    }
}
Posted
Updated 28-Jul-18 18:58pm
v2

1 solution

Quote:
My problem is the Greek characters printing something like symbols

The problem look like a mismatch between the printer settings and what you send to the printer.
I would particularly pay attention to characters encoding on both sides.
If your file include printer commands, the brand/model/language may matter too. But you did't gave details.
 
Share this answer
 
Comments
Stm21 29-Jul-18 5:18am    
I have a simple file .txt with ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ/αβγδεζηθικλμνξοπρστυφχψω
my thermal printer is LK-T20EB SEWOO
Patrice T 29-Jul-18 9:07am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
[no name] 29-Jul-18 7:32am    
The documentation for your product sucks.

You should be able to "select a font" ... except it doesn't say what fonts are available; or how to make them available.

You can print "images" ... except there is nothing about that either.

You should have picked a "better" (documented) product; add another 6 months to your project.
Patrice T 29-Jul-18 9:08am    
who are talking to ?
[no name] 29-Jul-18 15:59pm    
A confusing (for me) interface ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900