Dot Matrix Printer Does Not Resize Paper Size

0

I am using a dot matrix printer for receipt printing. I installed the same as Generic only text. But I send the print, it recognizes the height as A4 paper. How do I get the printer to cut paper when there are no characters.

Here is 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;

        }
    }
    
asked by anonymous 13.02.2017 / 14:15

2 answers

0

You can configure the printer instead of via code, place the paper type as a German continuous form and break-breaking:

    
13.02.2017 / 14:27
0

Assuming you are using Windows, go to the control panel and choose "Printers and Scanners" in the printer's "Printing Preferences" (where you usually choose the size of the printer page), there is a option to create a page size, click it and set the size according to your need.

    
13.02.2017 / 14:28