问题描述
我在 Winforms 中使用 C#.我正在尝试在纸卷上打印账单.纸张的宽度为 3 英寸,但纸张的长度是动态的(它是卷纸).长度取决于列表中有多少项目.例如.在一次购买中,如果有 100 件商品售出,那么它会很长,而对于单个购买的商品,它的长度会很短.
I am using C# with Winforms. I am trying to print bills on a paper roll. The width of the paper is 3in but the length of the paper is dynamic (its a roll paper). The length depends on how many items are there in the list. E.g. in a purchase if there are 100 items sold then it will be quite long roll while for a single item purchased it would be of small length.
当我打印报告时,在结束作业后,打印机弹出的最后一页比我需要的多.它会弹出与 A4 尺寸一样长的纸张.我想打印所需的行,然后停止打印.我使用一卷纸,而不是 A4 或 A3 和 Epson LQ-300 + II 打印机.
When I print the report, after the end job, printer eject the last page more than I need. It eject paper as long as A4 size. I want to print the required lines, then stop printing. I use a roll of paper, not A4 or A3 and an Epson LQ-300 + II printer.
更具体地说,总是按页面大小的单位进行打印.如果我将页面设置为 3 英寸 x 8 英寸,那么我总是会得到一个 8 英寸长的打印输出.如果我要打印一张 9 英寸的钞票,我最终会打印出 16 英寸的纸币,浪费了 7 英寸的纸张.我怎样才能在最后一页只打印需要的长度的情况下打印?
To be more specific, printing is always done to page-sized units. If I set the page to be 3in x 8in then I always end up with a printout that is a multiple of 8in long. If I have a 9in bill to print, I end up with a 16in printout, wasting 7in of paper. How can I print with the last page being only as long as it needs to be?
代码如下:
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;
}
推荐答案
你试过使用只有一行"长的页面吗?
Have you tried using a page that is only "one line" long?
省略上下边框,可以不间断打印.
Omit the upper and lower border, and you can print non stop.
现在添加一点(这样页面可以被撕掉)并弹出它.
Now add a bit (So the page can be torn off) and eject that.
试试这个:
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
这篇关于在卷纸上打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!