Print Width on Thermal Printer, WPF, and C #

1
Hello, I am making a program to print a list of activities on thermal printers, in it I put this information inside a table (created in code only for printing, with a total width of around 250, and a font size of 12) , and the table inside a FlowDocument and then print with the PrintDocument method of PrintDialog , the problem is that depending on the printer the content is being printed very large, and would like it to be of equal size on any thermal printer , whose width of the sheet follows the standard of 80mm. I already tried to turn the table into an image and try to get the width indicated in PrintDialog.PrintableAreaWidth and print as image with that width, but I did not succeed ...

In short: I need to get a way that the font size and print width are the same regardless of the printer thinking of 80mm papers.

    
asked by anonymous 20.11.2015 / 18:45

1 answer

1

The likely solution will be to adopt the standard ESC/POS believe that all thermal printers adopt this standard.

From experience, EPSON, ELGIN, BEMATECH, I have already tested, obviously some commands of this standard can apply to one model and another not, for example, paper cutting only works on a guillotine printer.

Here's a Example Usage

Documentation: Here

Code snippet (Full example in the link above):

Public Class Form1
    Public Const eClear As String = Chr(27) + "@"
    Public Const eCentre As String = Chr(27) + Chr(97) + "1"
    Public Const eLeft As String = Chr(27) + Chr(97) + "0"
    Public Const eRight As String = Chr(27) + Chr(97) + "2"
    Public Const eDrawer As String = eClear + Chr(27) + "p" + Chr(0) + ".}"
    Public Const eCut As String = Chr(27) + "i" + vbCrLf
    Public Const eSmlText As String = Chr(27) + "!" + Chr(1)
    Public Const eNmlText As String = Chr(27) + "!" + Chr(0)
    Public Const eInit As String = eNmlText + Chr(13) + Chr(27) + _
    "c6" + Chr(1) + Chr(27) + "R3" + vbCrLf
    Public Const eBigCharOn As String = Chr(27) + "!" + Chr(56)
    Public Const eBigCharOff As String = Chr(27) + "!" + Chr(0)

    Private prn As New RawPrinterHelper

    Private PrinterName As String = "EPSON TM-T20 Receipt"

    Public Sub StartPrint()
        prn.OpenPrint(PrinterName)
    End Sub

    Public Sub PrintHeader()
        Print(eInit + eCentre + "My Shop")
        Print("Tel:0123 456 7890")
        Print("Web: www.????.com")
        Print("sales@????.com")
        Print("VAT Reg No:123 4567 89" + eLeft)
        PrintDashes()
    End Sub

    Public Sub PrintBody()
        Print(eSmlText + "Tea                                          T1   1.30")

        PrintDashes()

        Print(eSmlText + "                                         Total:   1.30")

        Print("                                     Paid Card:   1.30")
    End Sub

    Public Sub PrintFooter()
        Print(eCentre + "Thank You For Your Support!" + eLeft)
        Print(vbLf + vbLf + vbLf + vbLf + vbLf + eCut + eDrawer)
    End Sub

    Public Sub Print(Line As String)
        prn.SendStringToPrinter(PrinterName, Line + vbLf)
    End Sub

    Public Sub PrintDashes()
        Print(eLeft + eNmlText + "-".PadRight(42, "-"))
    End Sub

    Public Sub EndPrint()
        prn.ClosePrint()
    End Sub

    Private Sub bnExit_Click(sender As System.Object, e As System.EventArgs) _
            Handles bnExit.Click
        prn.ClosePrint()

        Me.Close()
    End Sub

    Private Sub bnPrint_Click(sender As System.Object, e As System.EventArgs) _
            Handles bnPrint.Click
        StartPrint()

        If prn.PrinterIsOpen = True Then
            PrintHeader()

            PrintBody()

            PrintFooter()

            EndPrint()
        End If
    End Sub
End Class

Source: link

    
20.11.2015 / 20:02