0

enter image description here

image says all, there is 3 lines which not appears complete then when i print they dont see complete.

is there a property for this print the line down until this print all the complete line?

or the unique way is i count the letters by line and I do a WriteLine()?

this is a txt bulid in c#

Cod Ope Nombre Error Información adicional 39546 MICHEL ONTIVEROS PABLO IGNACIO error exec grabaped 10asdfdsfñljadñsklfjkadsjfjasdljfkñladsñlfjklajskldfjklñadskjlfañklsdjñklfkñladsñkjflklkñjadsHola mundo, hola mundo 2, hola como estas, esta es una cadena muy larga blablal etc whats 39547 BEBIDAS DE LOS ANGELES, S.A. error exec
39548 TAPON CORONA, S.A. DE C.V. error exec 42802 OPERADORA Q-LOGISTICS error exec 852 Unilever de México S.A de C.V error exec 851 Concesionaria de Productos Jag error exec
881 Municipio de Merida Yucatan error exec 846 Chetumal Q.Roo
error exec 40715 JUGOS DEL VALLE error exec
847 CanCun Q.Roo (Playa del Carmen error exec 39547 BEBIDAS DE LOS ANGELES, S.A. error exec grabaped 10asdfdsfñljadñsklfjkadsjfjasdljfkñladsñlfjklajskldfjklñadskjlfañklsdjñklfkñladsñkjflklkñjads 39548 TAPON CORONA, S.A. DE C.V. error exec grabaped 10asdfdsfñljadñsklfjkadsjfjasdljfkñladsñlfjklajskldfjklñadskjlfañklsdjñklfkñladsñkjflklkñjads

angel
  • 4,474
  • 12
  • 57
  • 89

2 Answers2

0

I believe there is not a property you can use. You can use the Graphics.MeasureString() method to check the length of your text against the width of your document. Also, take into account the print document's page margin - if you have set them. If your text is too long use the String.Split() method and write a new line.

Counting the letters is not a reliable way since some letters are wider than others depending on the font you use.

Atomic Star
  • 5,427
  • 4
  • 39
  • 48
0

I get thing I wanted doing it

 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

            string ruta = @"..\wbcimpresion"+destino+".txt";
            //borra si existe
            if (System.IO.File.Exists(ruta))
                System.IO.File.Delete(ruta);
             //creo mi archivo

                if (kryptonDataGridView1.Rows.Count > 0)
                {
                    System.IO.StreamWriter escritor = new System.IO.StreamWriter(ruta);


                    for (int columna = 0; columna < kryptonDataGridView1.Columns.Count; columna++)
                    {
                        escritor.Write(kryptonDataGridView1.Columns[columna].HeaderText.ToString()+"\t\t");
                    }


                    for (int fila = 0; fila < kryptonDataGridView1.Rows.Count; fila++)
                    {
                        escritor.WriteLine();
                        System.IO.StringWriter stringescritor = new System.IO.StringWriter();
                        for (int columna = 0; columna < kryptonDataGridView1.Columns.Count; columna++)
                        {


                            stringescritor.Write
                                (
                               kryptonDataGridView1.Rows [fila].Cells [columna ].Value.ToString ()+"\t"

                                );

                        }

                        string dato = stringescritor.ToString();

                        if (dato.Length > 120)
                        {
                            int contador1 = 0;
                            while (dato.Length > 120)
                            {
                                if (contador1 == 0)
                                    escritor.Write(dato.Substring(0, 120));
                                else
                                {
                                    escritor.WriteLine();
                                    escritor.Write(dato.Substring(0, 120));
                                }
                                dato = dato.Remove(0, 120);
                                contador1++;
                            }
                            escritor.WriteLine();
                            escritor.Write (dato.Substring (0,dato.Length ));


                        }
                        else
                        { 
                        escritor.Write (dato.Substring (0,dato.Length ));
                        }
                    }
                    escritor.Flush();
                    escritor.Close();
                    escritor.Dispose();
                }



            string imprimeme = "";
            System.IO.StreamReader lector = new System.IO.StreamReader (ruta);
            imprimeme = lector.ReadToEnd();

            lector.Close();
            lector.Dispose();
            float leftMargin = e.MarginBounds.Left;
            float rightMargin = e.MarginBounds.Right;
            leftMargin = 40;
            rightMargin = 60;
            printDocument1.DefaultPageSettings.Landscape = true;

            e.Graphics.DrawString(imprimeme, new Font("Arial", 11, FontStyle.Regular ), Brushes.Black, leftMargin, rightMargin);





        }
angel
  • 4,474
  • 12
  • 57
  • 89