I'll try. I assume that you are using a set of printing libraries that work well at a high level, but you should use something more "manual". My dad has a cafe, and I made him software for software. The receipt printer prints only those lines that are needed for the code that I will give you. I guess moving in this way might work for you.
This method does not print images, only text, which is important to know.
The printing methods in my code seem to be different from yours; they are "sensitive to characters." This means that if you need 3 spaces, then you have to write 3 spaces and then the text.
To run this code, you will need to create ".txt" and then send this text file as an argument to the print class. I'm not sure if you are using C # or VB, my code is in C #.
So, firstly, to create a text file anywhere in your program, you need a heading:
using System.IO;
Then at the point you need to start the text file:
StreamWriter sw = new StreamWriter("receipt.txt");
This creates a file in your current folder - the same your .exe is located at. It will also overwrite the old ones, so you don’t have to worry about whether a file with the same name already existed. To write your receipt lines, you will use:
sw.WriteLine(" the text is supposed to be written, you may use concatenations ");
The WriteLine method writes a line of text to a file and then moves on to the next line.
When you finish writing, you need to close the file with ...
sw.Close();
You will need to call the print class that I give you. Assuming you already have this, you need to instantiate it, as in:
PimpMyPrint p = new PimpMyPrint();
And then call the PrintDoc method with ...
p.PrintDoc("receipt.txt");
Once again, you need a class with all the necessary methods. I DO NOT ACCEPT CREDIT FOR THIS CLASS; This is the work of the author Francisco Javier Cebalos from Spain. Mr. Cebalos is a well-known author in the Spanish SD community, and this is from his book "Microsoft C # Curso de programación".
So here is the class you need to add:
using System; using System.IO; using System.Drawing; using System.Drawing.Printing; namespace SomeNamespace { class PimpMyPrint { private Font font; private StreamReader sr; public void PrintDoc(string textfile) { try { sr = new StreamReader(textfile); try { font = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(this.PrintPage); pd.Print(); } finally { sr.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } } private void PrintPage(object obj, PrintPageEventArgs ev) { float LinesPerPage = 0; float pos_Y = 0; int count = 0; float marginLeft = ev.MarginBounds.Left; float marginUP = ev.MarginBounds.Top; string line = null; float fontHeight = font.GetHeight(ev.Graphics); LinesPerPage = ev.MarginBounds.Height / fontHeight; while (count < LinesPerPage && ((line = sr.ReadLine()) != null)) { pos_Y = marginUP + (count * fontHeight); ev.Graphics.DrawString(line, font, Brushes.Black, 0, pos_Y, new StringFormat()); count++; } if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } } }
I hope this works for you as well as it worked for me!