无法使用Printdocument在文本文件中打印多字符

时间:2018-06-15 06:19:05

标签: c# printdocument

我需要在热敏打印机上打印包含147行的文本文件。 它会在第96行停止打印并且不会继续。

我一直在搜索如何使用HasMorePages功能,但我被卡住了。 它没有按预期工作。它不打印全文文件。 它只在第一页停止

请帮忙

这是我的代码

        public void print_m()
        {

        PrintDocument pdoc_merc = new PrintDocument();

        PrintDialog pd = new PrintDialog();

        PrinterSettings ps = new PrinterSettings();
        Font font = new Font("Calibri (Body)", 10);

        //remove printing dialog
        PrintController printController = new StandardPrintController();
        pdoc_merc.PrintController = printController;

        pdoc_merc.PrintPage += new PrintPageEventHandler(ReadFile);


        pdoc_merc.PrinterSettings.PrinterName = SelectedPrinter.ToString();

        pdoc_merc.Print();

        string GS = Convert.ToString((char)29);
        string ESC = Convert.ToString((char)27);

    }

       private void ReadFile(object sender, PrintPageEventArgs e)
    {
        Graphics graphics = e.Graphics;
        Font font = new Font("Calibri (Body)", 10);
        float fontHeight = font.GetHeight();
        int startX = 0;
        int startY = 0;


        TextReader tr = new StreamReader(@"C:\\Ingenico\\" + "merchant.txt");

        //How many lines should be loaded?
        int NumberOfLines = 147;

        //Make our array for each line
        string[] ListLines = new string[NumberOfLines];

       // MessageBox.Show("MarginBoundsHeight"  +  e.MarginBounds.Height.ToString());

        initial_height = e.MarginBounds.Height; 

        for (int i = 1; i < 147; i++)
        {

            Font myFont = new Font("m_svoboda", 14, FontStyle.Underline, GraphicsUnit.Point);

            float lineHeight = myFont.GetHeight(e.Graphics) + 4;

            float yLineTop = e.MarginBounds.Top;

            if (yLineTop + lineHeight > e.MarginBounds.Bottom)
            {
                e.HasMorePages = true;

                return;
            }


            ListLines[i] = tr.ReadLine();  
            graphics.DrawString(ListLines[i],new Font("Calibri (Body)", 8),new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 12;

            yLineTop += lineHeight;



        }

        e.HasMorePages = false;



    }

`

0 个答案:

没有答案