Search code examples
c#printingopos

OPOS reciept remove top margin


I'm using OPOS commands to print receipts using C#. All the receipts I print comes with a large top margin. I have tested this with both epson and xprinter and the results are same. Are there any workaround for this?

My codes are given below

public bool OpenPrint(string szPrinterName)
    {
        if (PrinterOpen == false)
        {
            di.pDocName = ".NET RAW Document";
            di.pDataType = "RAW";

            if (OpenPrinter(szPrinterName.Normalize(), ref hPrinter, IntPtr.Zero))
            {
                if (StartDocPrinter(hPrinter, 1, di))
                {
                    if (StartPagePrinter(hPrinter))
                        PrinterOpen = true;
                }
            }
        }

        return PrinterOpen;
    }

public bool SendStringToPrinter(string szPrinterName, string szString)
    {
        if (PrinterOpen)
        {
            IntPtr pBytes;
            Int32 dwCount;
            Int32 dwWritten = 0;

            dwCount = szString.Length;

            pBytes = Marshal.StringToCoTaskMemAnsi(szString);

            var res = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
            Marshal.FreeCoTaskMem(pBytes);
            return res;
        }
        else
            return false;
    }

public void ClosePrint()
    {
        if (PrinterOpen)
        {
            EndPagePrinter(hPrinter);
            EndDocPrinter(hPrinter);
            ClosePrinter(hPrinter);
            PrinterOpen = false;
        }
    }

enter image description here


Solution

  • This is generally due to the gap between the printhead and paper cutter.
    Due to the physical position, no printer is more or less immune to it.

    However, some printers can reduce the margins by special feature/mode settings in the firmware.
    Please ask your printer vendor if your printer has such a feature/mode, and if so, how to use it.

    For printers that do not have such a feature/mode, the general process is to print the beginning of the next receipt before cutting the paper each time a receipt is printed.