0
votes

I have written a code in c# by using graphic object to print the receipt on POS printer (EPSON TM-T82 - paper roll : 80 X 297 mm).

sample code is as follow

Graphics graphic = e.Graphics;
Font regularFont = new Font("Courier New", 8);
Font titleFont = new Font("Courier New", 14);
SolidBrush drawBrush = new SolidBrush(Color.Black);
float fontHeight = regularFont.GetHeight();
float startX = 10.0F;
float startY = 5.0F;
int offset = 40;
graphic.DrawString("----------------------------------------", regularFont, drawBrush, new PointF(startX, startY+offset), StringFormat.GenericTypographic);
offset = offset + (int)fontHeight + 5;
string header = "Item Name".PadRight(30) + "Price";
graphic.DrawString(header, regularFont, drawBrush, , new PointF(startX, startY+offset), StringFormat.GenericTypographic);
offset = offset + (int)fontHeight;
graphic.DrawString("----------------------------------------", regularFont, drawBrush, new PointF(startX, startY+offset), StringFormat.GenericTypographic);

and so on....

Now issue is that while exporting into ".XPS" then it is showing perfect. But while printing on POS printer receipt; it cuts the columns. Meaning to say that it is not printing the full row of string. I tried to fix this issue by passing RectangleF in graphic.DrawString as per suggestions found over internet but same issue.

Please see the attached screenshots of .XPS and POS receipt

enter image description here enter image description here

Here, in screenshot, the receipt border is marked as black. in .XPS the row is printing perfect (taking full page width) but in POS printer receipt, it is not taking full width (see the white space from cut character to right side border)

If anyone can help me here what exactly i am doing wrong.

Thanks in advance.

1
Try changing your regularFont size a bit smaller to see what it produces. Post resultsJuan Carlos
I reduced the regular font size (4) and now it prints the receipt without any missing row text but fonts are very small and not even properly readable on printed receipt. I don't want to reduce the font size here. Do you have any other suggestion or solution ?JPS
If now fits after changing the font size, then the problem is a design one. Two solutions: smaller size or simplify data. For example you can take the [email protected] and put it in two rows.Juan Carlos
Hi Juan, I have modified my original query, Please see the comment again that added just after the new screenshots (with black borders).JPS
Using the printer driver for a POS printer is wrong in 98% of all cases. Biggest issue is that it is just too slow and the customer has to wait too long to get his receipt. And the small stuff, like not having a meaningful page size for paper on a roll. The one you used isn't wide enough. Doing it correctly requires writing the print commands directly to the printer, bypassing the driver. support.microsoft.com/en-us/kb/322091Hans Passant

1 Answers

1
votes

Please use the columnwidth propertie
FlowDocument doc = new FlowDocument(); doc.ColumnWidth = 700; doc.PagePadding = new Thickness(20, 0, 0, 0);

I wish this will help others