2

从过去2天一直在寻找这个无法解决,终于我来了。现在从问题开始,
如何在点阵打印机上打印收据并在打印一张收据后停止,而不继续从 C# 打印带有空格的完整页面,我能够使用下面的 JScript 代码进行打印,但继续打印整个页面即使在接收完成后。

   function Print-content() {              
           var DocumentContainer = document.getElementById('div2');  
           var WindowObject = window.open('', "PanelDetails"
             ,"width=1000,height=550,top=100
             ,left=150,toolbars=no,scrollbars=yes
             ,status=no,resizable=no");
           WindowObject.document.writeln(DocumentContainer.innerHTML);
           WindowObject.document.close(); 
           WindowObject.focus();  
           WindowObject.open();               
           WindowObject.print();               
       }

但是在打印半页后,打印机并没有停止它继续打印带有空格的完整页面,这是在许多网站上看到的常见问题但没有提出解决方案,因此已转向使用 ITextSharp Dll 的服务器端编码。

有人可以帮我提供打印收据半页的完整解决方案,并在打印页面的最后一行后停止打印机,这是 Letter Fanfold 8-1/2'' 11'' 尺寸的垂直一半。

如果需要,为了更清楚,我也会发布 C# 代码,但为了不弄乱我忽略了代码

提前致谢

这是我的 C# 代码

 StringReader sr;
 private void ExportDataListToPDF()
{

   using (PrintDocument doc = new PrintDocument())
    {
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.div2.RenderControl(hw);
    sr = new StringReader(sw.ToString());         
    doc.DocumentName = "Hello";
    doc.DefaultPageSettings.Landscape = false;   
     PaperSize psize = new PaperSize("MyCustomSize", 216, 279);
     doc.DefaultPageSettings.PaperSize = psize;
     doc.PrinterSettings.DefaultPageSettings.PaperSize = psize;
     psize.RawKind = (int)PaperKind.Custom;
    doc.PrinterSettings.DefaultPageSettings.PaperSize.Height = doc.PrinterSettings.DefaultPageSettings.PaperSize.Height / 2;
    doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
    doc.PrinterSettings.PrinterName = "EPSON LQ-1150II";
    doc.PrintController = new StandardPrintController();
   // doc.PrinterSettings.PrintFileName = sw.ToString();
    doc.Print();
    }

    }

    public void doc_PrintPage(object sender, PrintPageEventArgs ev)
{
System.Drawing.Font printFont = new System.Drawing.Font(FontFamily.GenericSerif, 12);
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;

// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
   printFont.GetHeight(ev.Graphics);

// Print each line of the file.
while (count < linesPerPage &&
   ((line = sr.ReadLine()) != null))
{
    yPos = topMargin + (count *
       printFont.GetHeight(ev.Graphics));
    ev.Graphics.DrawString(line, printFont, Brushes.Black,
       leftMargin, yPos, new StringFormat());
    count++;
}

// If more lines exist, print another page.
if (line != null)
    ev.HasMorePages = true;
else
    ev.HasMorePages = false;
}
4

0 回答 0