3

Is there a way to ignore page feed for thermal printers while using the PrintDocument? In terms of printing a "receipt", if there are a lot of items on it (100's) the printer always puts a blank space between items where it thinks there should be a page feed.

My problem is there is no pages to feed, it's a continuous roll of paper.

In the printer drivers, via right clicking printer -> Printer Preferences -> Document Settings Tab; I have set the Paper Source to Page[NoFeed,Cut] and Document[NoFeed,Cut] but I still have the same issue.

I have also tried setting a "User Defined Paper Size" but it seems the EPSON drivers do not support this. My idea here was that I would just set the page height very long. Edit I have been able to try setting the printer to use a form that is 3276.00cm long but I still have the same issue. I have also tried setting the printer up as a generic printer and I still see the same issue

Here is the code I am using, perhaps there is a way to do this on the fly, in code?

  private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {


            int charactersOnPage = 0;
            int linesPerPage = 0;

            // Sets the value of charactersOnPage to the number of characters 
            // of stringToPrint that will fit within the bounds of the page.
            e.Graphics.MeasureString(pageString, this.Font,
                e.MarginBounds.Size, StringFormat.GenericTypographic,
                out charactersOnPage, out linesPerPage);

            // Draws the string within the bounds of the page
            e.Graphics.DrawString(pageString, this.Font, Brushes.Black,
                e.MarginBounds, StringFormat.GenericTypographic);

            // Remove the portion of the string that has been printed.
            pageString = pageString.Substring(charactersOnPage);

            // Check to see if more pages are to be printed.
            e.HasMorePages = (pageString.Length > 0);
        }




    private void metroButton2_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < 200; i++)
        {
            pageString += "Salesitem " + i.ToString() + " \n";
        }

        bool online = printDocument1.PrinterSettings.IsValid;
        if (online)
            printDocument1.Print();
        else
            MessageBox.Show("Printer Offline");

    }

Thank you very much for your time. I have seen some similar questions on SO, but most that I can understand rely on using the driver to solve this issue. This is not applicable for me because I have two requirements from my boss their driver for my printer and older models does not support creating custom page sizes directly from within the driver, nor does it seem to work for disabling the page feed. I need a way to solve this issue via code if possible.

Edit: I feel like I have tried everything. I have tried sending the data to the printer in chunks, but the problem is, every time printDocument1_PrintPage is executed by checking e.HasMorePages = (pageString.Length > 0);, the page feed command or line feed command is being sent to the printer (TMT 88IV, TMT 88II) even though in the driver I have it set to a roll of paper.

I have also tried using a custom paper kind, and starting with a small paper height, and dynamically adding to the paper height every time I draw a line, but still, it's like the paper height set in code and by the printer driver (it's set to be 3276.00cm long in the driver) is ignored every time the page event is raised.

The only way I have been able to get around this is using the RawPrinterHelper class, and send the print commands myself. Yes this is easy but I would love to be able to easily use the .net features for fonts, picture printing, queue monitoring ect. It's a shame, literally the only thing stopping me is this tremendous spacing automatically inserted on continuous roll paper on receipts longer than standard page height.

clamchoda
  • 4,411
  • 2
  • 36
  • 74
  • Using PrintDocument on a thermal printer is almost never correct. Most important thing you need to do right now is to talk to the customer and ask him how much time you have to print a receipt. If you can't get a response then assume "no more than a second". Measure how long it takes now. Assuming the typical outcome, tell your boss you need another 2 months to do it right. – Hans Passant Dec 01 '16 at 18:06
  • @Hans Passant I actually have a working solution using the RawPrinterHelper and manually sending the printercommands which was quite quickly whipped up from here if anyone is interested https://support.microsoft.com/en-us/kb/322091 But I would still love to know the solution using the PrintDocument if anyone could share their findings it would be appreciated. Thank you – clamchoda Dec 02 '16 at 15:57
  • That is the correct solution. – Hans Passant Dec 02 '16 at 16:01
  • @clamchoda It looks like you are telling the printer that the page has ended by closing out your `_PrintPage` with setting it to another page. Is there any manner for you to send all data at once so you have no more "pages" remaining at the end? `while (pageString.Length > ){ //Continue printing lines }` – vipersassassin Dec 03 '16 at 13:29
  • @viperassassin I have also tried that too. Sending it all at once as a formatted string and trying to set a large page length in both code and printer drivers. Hans Passant is correct, I just wish he wasn't :D It's silly this one paging feature that can't be overridden ruins the PrintDocument implementation for thermal printers. – clamchoda Dec 05 '16 at 17:55
  • Did you check this out: http://stackoverflow.com/questions/14659210/increasing-paper-height-per-iteration-using-printdocument ? – Max Senft Dec 08 '16 at 18:07
  • @Max Senft I did sir, but it is not a viable solution for all printers. Specifically, the EPSON TMT-88IV and older series, which are still widely used among the restaurant industry ;/ Edit: By not viable, I mean it doesn't work. Still produces the same result on some printers – clamchoda Dec 09 '16 at 18:42

0 Answers0