Hai. I have a problem regarding bill printing on roll paper. My printer is Epson LX-300+II, my roll paper is about 3" width, and is used for printing bill/invoices for the customers. The number of items varies.

Whenever I finished printing the bill, the printer throws out/ejects the paper, as long as about a letter (11") size. Whatever the ways to achieve this, I just want the printer stop printing/ejecting after the last line, then i can tear off the bill for my customers without wasting paper.

I'm really wondering someone out there could help me.. I have worked hard for this, and searched in internet, but it seems that there's no applicable and clear solution. If the solution is in VB, please give me the code to implement this, or give me a very simple example application.

And there is also a problem, I cannot make a custom size in my printing preference. (What's wrong with this?)

Anyway, I thank u very much for your helps

Edited 6 Years Ago by acidking001: n/a

You are unfortunately in the wrong forum if you are using vb 2008. You should post this in vb.net.

If you were to use vb6, you would have used something like -

Printer.CurrentX
Printer.CurrentY
Printer.DrawWidth
Printer.EndDoc 'To stop printing
Printer.Height
Printer.KillDoc
'etc, etc, etc.

Please repost this in vb.net

Hai. I have a problem regarding bill printing on roll paper. My printer is Epson LX-300+II, my roll paper is about 3" width, and is used for printing bill/invoices for the customers. The number of items varies.

Whenever I finish printing the bill, the printer throws out/ejects the paper, as long as about a letter (11") size. Whatever the ways to achieve this, I just want the printer stop printing/ejecting after the last line, then i can tear off the bill for my customers without wasting paper.

I'm really wondering someone out there could help me.. I have worked hard for this, tested some suggestions and codes, and searched in internet, but it seems that there's no applicable or clear solution. I also tested it in ms word, setting the page size to 3" x 3", and typed several words, but the printer is still wasting the paper. If the solution is in VB, please give me the code to implement this, or give me a very simple example application.

And there is also a problem, there is no custom size in my printing preference. In printer & faxes window, I click server properties, and add a custom size, but in printing preference, the papersize i have created doesn't exist. (What's wrong with this?)

Anyway, I thank u very much for your helps

Edited 6 Years Ago by acidking001: n/a

Well, I will reply to my own post coz I've found a good solution.

Imports System.Runtime.InteropServices
Module mdlprint
    Public Class RawPrinter
        ' ----- Define the data type that supplies basic
        '       print job information to the spooler.
        <StructLayout(LayoutKind.Sequential, _
            CharSet:=CharSet.Unicode)> _
        Public Structure DOCINFO
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pDocName As String
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pOutputFile As String
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pDataType As String
        End Structure

        ' ----- Define interfaces to the functions supplied
        '       in the DLL.
        <DllImport("winspool.drv", EntryPoint:="OpenPrinterW", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function OpenPrinter( _
           ByVal printerName As String, ByRef hPrinter As IntPtr, _
           ByVal printerDefaults As Integer) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function ClosePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="StartDocPrinterW", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function StartDocPrinter( _
           ByVal hPrinter As IntPtr, ByVal level As Integer, _
           ByRef documentInfo As DOCINFO) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="EndDocPrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function EndDocPrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="StartPagePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function StartPagePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="EndPagePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function EndPagePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="WritePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function WritePrinter( _
           ByVal hPrinter As IntPtr, ByVal buffer As IntPtr, _
           ByVal bufferLength As Integer, _
           ByRef bytesWritten As Integer) As Boolean
        End Function

        Public Shared Function PrintRaw( _
              ByVal printerName As String, _
              ByVal origString As String) As Boolean
            ' ----- Send a string of  raw data to  the printer.
            Dim hPrinter As IntPtr
            Dim spoolData As New DOCINFO
            Dim dataToSend As IntPtr
            Dim dataSize As Integer
            Dim bytesWritten As Integer

            ' ----- The internal format of a .NET String is just
            '       different enough from what the printer expects
            '       that there will be a problem if we send it
            '       directly. Convert it to ANSI format before
            '       sending.
            dataSize = origString.Length()
            dataToSend = Marshal.StringToCoTaskMemAnsi(origString)

            ' ----- Prepare information for the spooler.
            spoolData.pDocName = "Print Document"
            spoolData.pDataType = "RAW"

            Try
                ' ----- Open a channel to  the printer or spooler.
                Call OpenPrinter(printerName, hPrinter, 0)

                ' ----- Start a new document and Section 1.1.
                Call StartDocPrinter(hPrinter, 1, spoolData)
                Call StartPagePrinter(hPrinter)

                ' ----- Send the data to the printer.
                Call WritePrinter(hPrinter, dataToSend, _
                   dataSize, bytesWritten)

                ' ----- Close everything that we opened.
                EndPagePrinter(hPrinter)
                EndDocPrinter(hPrinter)
                ClosePrinter(hPrinter)
            Catch ex As Exception
                MsgBox("Error occurred: " & ex.ToString)
            Finally
                ' ----- Get rid of the special ANSI version.
                Marshal.FreeCoTaskMem(dataToSend)
            End Try
        End Function
    End Class
End Module

How to use:

RawPrinter.PrintRaw("Epson LQ-2180 ESC/P 2", "test")
Comments
For finding AND posting the solution yourself.

Well, I will reply to my own post coz I've found a good solution.

Imports System.Runtime.InteropServices
Module mdlprint
    Public Class RawPrinter
        ' ----- Define the data type that supplies basic
        '       print job information to the spooler.
        <StructLayout(LayoutKind.Sequential, _
            CharSet:=CharSet.Unicode)> _
        Public Structure DOCINFO
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pDocName As String
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pOutputFile As String
            <MarshalAs(UnmanagedType.LPWStr)> _
               Public pDataType As String
        End Structure

        ' ----- Define interfaces to the functions supplied
        '       in the DLL.
        <DllImport("winspool.drv", EntryPoint:="OpenPrinterW", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function OpenPrinter( _
           ByVal printerName As String, ByRef hPrinter As IntPtr, _
           ByVal printerDefaults As Integer) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function ClosePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="StartDocPrinterW", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function StartDocPrinter( _
           ByVal hPrinter As IntPtr, ByVal level As Integer, _
           ByRef documentInfo As DOCINFO) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="EndDocPrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function EndDocPrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="StartPagePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function StartPagePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="EndPagePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function EndPagePrinter( _
           ByVal hPrinter As IntPtr) As Boolean
        End Function

        <DllImport("winspool.drv", EntryPoint:="WritePrinter", _
           SetLastError:=True, CharSet:=CharSet.Unicode, _
           ExactSpelling:=True, _
           CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function WritePrinter( _
           ByVal hPrinter As IntPtr, ByVal buffer As IntPtr, _
           ByVal bufferLength As Integer, _
           ByRef bytesWritten As Integer) As Boolean
        End Function

        Public Shared Function PrintRaw( _
              ByVal printerName As String, _
              ByVal origString As String) As Boolean
            ' ----- Send a string of  raw data to  the printer.
            Dim hPrinter As IntPtr
            Dim spoolData As New DOCINFO
            Dim dataToSend As IntPtr
            Dim dataSize As Integer
            Dim bytesWritten As Integer

            ' ----- The internal format of a .NET String is just
            '       different enough from what the printer expects
            '       that there will be a problem if we send it
            '       directly. Convert it to ANSI format before
            '       sending.
            dataSize = origString.Length()
            dataToSend = Marshal.StringToCoTaskMemAnsi(origString)

            ' ----- Prepare information for the spooler.
            spoolData.pDocName = "Print Document"
            spoolData.pDataType = "RAW"

            Try
                ' ----- Open a channel to  the printer or spooler.
                Call OpenPrinter(printerName, hPrinter, 0)

                ' ----- Start a new document and Section 1.1.
                Call StartDocPrinter(hPrinter, 1, spoolData)
                Call StartPagePrinter(hPrinter)

                ' ----- Send the data to the printer.
                Call WritePrinter(hPrinter, dataToSend, _
                   dataSize, bytesWritten)

                ' ----- Close everything that we opened.
                EndPagePrinter(hPrinter)
                EndDocPrinter(hPrinter)
                ClosePrinter(hPrinter)
            Catch ex As Exception
                MsgBox("Error occurred: " & ex.ToString)
            Finally
                ' ----- Get rid of the special ANSI version.
                Marshal.FreeCoTaskMem(dataToSend)
            End Try
        End Function
    End Class
End Module

How to use:

RawPrinter.PrintRaw("Epson LQ-2180 ESC/P 2", "test")
This question has already been answered. Start a new discussion instead.