Matrix Printer does not reconfigure paper size

Asked

Viewed 567 times

0

I am using a dot matrix printer to print receipts. I installed it as Generic text only. But send the print, it recognizes the height as A4 paper. How to make the printer cut the paper when there are no characters.

Follow the code used:

 public class CPrint
    {
        protected StringReader stringToPrint;
        protected Font printFont;

        public int altura { get; set; }

        public int tam { get; set; }


        public CPrint()
        {
        }


        public void PageCreate(string printerName, string file)
        {
            CFormatacao formatar = new CFormatacao();
            StringBuilder sb = new StringBuilder();
            string qs = "";
            //try
            //{
                string texto = "";
                int qtdLinha = 0;
                StreamReader arq = new StreamReader(file, System.Text.Encoding.Default, false, 512);

                while (!arq.EndOfStream)
                {
                    texto += arq.ReadLine() + System.Environment.NewLine;
                    qtdLinha++;
                }

                //for (int i = 0; i < 10; i++)
                //{
                //    texto += System.Environment.NewLine;
                //}

                texto = formatar.RemoveAcentos(texto);
                altura = qtdLinha +10;
                arq.Close();


                stringToPrint = new StringReader(texto);
                printFont = new Font("Arial", 12);

                PrintDocument doc = new PrintDocument();

                doc.PrinterSettings.PrinterName = printerName;

                tam = 827 * altura;
                tam = formatar.ConverteEmInteiro(Math.Round(tam/75M).ToString());
                //Configura um novo papel
                PaperSize ps = new PaperSize("MT", 827, tam);
                doc.DefaultPageSettings.PaperSize = ps;

                doc.PrintPage += new PrintPageEventHandler(this.PagePrint);
                // print the page
                doc.Print();
                stringToPrint.Close();

                qs = "~/frmMensagem.aspx?msg=Recibo Impresso!";



            HttpContext.Current.Response.Redirect(qs);
        }



        private void PagePrint(object sender, PrintPageEventArgs e)
        {
            float linesPerPage = 0;
            float linePosition = 0;
            int lineCount = 0;

            float leftMargin = 5;
            float topMargin = 5;
            String line = null;

            linesPerPage = altura;//e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
            //linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);

            while (lineCount < linesPerPage && ((line = stringToPrint.ReadLine()) != null))
            {
                linePosition = topMargin + (lineCount * printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, linePosition, new StringFormat());
                lineCount++;

                if (true)
                {

                }

            }
            line = null;

            if (line != null )
                e.HasMorePages = true;
            else
                e.HasMorePages = false;

        }
    }

2 answers

0


You can configure the printer instead of making via code, put the paper type as a continuous German form and cut with break :

inserir a descrição da imagem aqui

  • Beyond this code in the image.

  • http://www.hetec.inf.br/base/diminuir-o-avanco-de-papel-no-driver-de-impressora-generica-do-windows/

  • That’s right, Igor Baesse. Thank you!

0

Assuming you are using Windows, go to the control panel and choose the "Printers and Scanners" option, in the "Print Preferences" of the said printer (where you usually choose the size of the printer page), there is an option to create a page size, click on it and define the size as your need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.