在卷纸上打印

我正在使用带Winforms的C#。 我想在纸卷上打印钞票。 纸张的宽度为3英寸,但纸张的长度是动态的(它是卷纸)。 长度取决于列表中有多少项。 例如,在购买时如果有100件商品售出那么它将是相当长的卷,而对于购买的单件商品它将是很小的长度。

当我打印报告时,在结束作业之后,打印机会弹出最后一页而不是我需要的页面。 只要A4尺寸就可以弹出纸张。 我想打印所需的行,然后停止打印。 我使用一卷纸,而不是A4或A3和Epson LQ-300 + II打印机。

更具体地说,始终对页面大小的单元进行打印。 如果我将页面设置为3英寸x 8英寸,那么我总是打印出8英寸长的打印输出。 如果我要打印一张9英寸的钞票,我最终会打印出16英寸的纸张,浪费7英寸的纸张。 如何打印最后一页只需要它就可以了?

这是代码:

private void printDoc_PrintPage(Object sender, PrintPageEventArgs e) { Font printFont = new Font("Courier New", 12); int y = 15; e.Graphics.DrawString("a Line", printFont, Brushes.Black, 0, y); y = y + 20; e.Graphics.DrawString(" Line", printFont, Brushes.Black, 0, y); y = y + 25; e.Graphics.DrawString(" Line", printFont, Brushes.Black, 0, y); y = y + 35; e.Graphics.DrawString(" Line", printFont, Brushes.Black, 0, y); y = y + 45; } 

您是否尝试使用仅“一行”长的页面?

省略上下边框,可以不停打印。

现在添加一点(这样可以将页面撕掉)并弹出它。

试试这个:

  PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200); printDoc.DefaultPageSettings.PaperSize = pkCustomSize1 

请参阅: http : //msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.papersize.aspx

您还可以动态调整纸张尺寸。 减少每页一行的工作量,但我想如果有人有理由这样做会产生更好的打印预览:

 printdoc.DefaultPageSettings.PaperSize.Height += lineheight; 

您可以在此处定义自定义纸张尺寸并在报告中使用它。

打开打印机文件夹(从控制面板)。

从文件菜单中打开服务器属性 。 它将打开“ 打印机和服务器属性对话框”。

选择“检查创建新表单”

指定页面宽度高度。 我建议你让你的身高3英寸。

现在单击“ 保存表单”按钮。

您的自定义页面已准备就绪

将此纸张设置为报告和打印机属性中的默认纸张尺寸。

现在你很高兴。

您还可以使用打印预览选项来完成此过程。

 // This is for the print preview event private void printPreviewDialog1_Load(object sender, EventArgs e) { int j = 0; z = 185; while (j < dataGridView1.Rows.Count) { j += 1; z += 30; } z += 60; PaperSize pkCustomSize1 = new PaperSize("First custom size", 350, z); printDocument1.DefaultPageSettings.PaperSize = pkCustomSize1; } // This is the loop for generating print Document private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int i = 0; //For Gridview Row Count int sno = 1; //For Grid Serial Number e.Graphics.DrawString( "HEADING", new Font("Calibri", 20, FontStyle.Bold), Brushes.Black, new Point(100, 5)); e.Graphics.DrawString( "Address", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, new Point(75, 35)); int y = 185; //For Grid y axis start to print while (i < dataGridView1.Rows.Count) { e.Graphics.DrawString( sno.ToString(), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(10, y)); //For Serial Number e.Graphics.DrawString( dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(240, y)); //This is for Trim content to next line Graphics df1 = e.Graphics; SizeF ef1 = df1.MeasureString( dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), new Font(new FontFamily("Calibri"), 12F, FontStyle.Bold), 200); //160 df1.DrawString( dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), new Font(new FontFamily("Calibri"), 12F, FontStyle.Bold), Brushes.Black, new RectangleF(new PointF(60.0F, y), ef1), //350.0 StringFormat.GenericTypographic); i += 1; sno += 1; y += 30; } e.Graphics.DrawString( "------------------------------------------------------------------------------------", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(0, y)); e.Graphics.DrawString( "Total Amount-:" + TotalAmnt_txt.Text, new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(150, y+=20)); e.Graphics.DrawString( "------------------------------------------------------------------------------------", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(0, y+=20)); e.Graphics.DrawString( "***Care For You ****", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(150, y += 20)); i = 0; sno = 1; }