Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting a reciept on Dot matrix printer with custom paging from C#, asp.net
    primarykey
    data
    text
    <p>Have been looking for this from past 2days couldn't sort out, finally im here. Now starting with the Question,<br> How to Print a reciept on dot matrix printer and stop after printing one reciept with out continuing to prnt complete page with white spaces from C#, iam able to print using the below JScript code, but continues to print whole page even after reciept is completed. </p> <pre><code> 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(); } </code></pre> <p>But after printing half page, printer doesnt stop it proceeds and prints complete page with white spaces, well thats a usual problem seen on many sites but didn't come up with a solution, So have shifted to server side coding, using ITextSharp Dll.</p> <p>Can some one please help me with complete solution for printing a reciept half Page and stop the printer after printing last line of the page, which is vertical half of the Letter Fanfold 8-1/2'' 11'' size.</p> <p>for more clarity if required i will post C# code aswell, but in order not to mess i ignored the code</p> <p>Thanks in advance</p> <p>Here's my C# code</p> <pre><code> 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 &lt; linesPerPage &amp;&amp; ((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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload