0
I am using a dot matrix printer to print receipts. I installed it as Generic text only. But send the print, it recognizes the height as A4 paper. How to make the printer cut the paper when there are no characters.
Follow the code used:
public class CPrint
{
protected StringReader stringToPrint;
protected Font printFont;
public int altura { get; set; }
public int tam { get; set; }
public CPrint()
{
}
public void PageCreate(string printerName, string file)
{
CFormatacao formatar = new CFormatacao();
StringBuilder sb = new StringBuilder();
string qs = "";
//try
//{
string texto = "";
int qtdLinha = 0;
StreamReader arq = new StreamReader(file, System.Text.Encoding.Default, false, 512);
while (!arq.EndOfStream)
{
texto += arq.ReadLine() + System.Environment.NewLine;
qtdLinha++;
}
//for (int i = 0; i < 10; i++)
//{
// texto += System.Environment.NewLine;
//}
texto = formatar.RemoveAcentos(texto);
altura = qtdLinha +10;
arq.Close();
stringToPrint = new StringReader(texto);
printFont = new Font("Arial", 12);
PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName = printerName;
tam = 827 * altura;
tam = formatar.ConverteEmInteiro(Math.Round(tam/75M).ToString());
//Configura um novo papel
PaperSize ps = new PaperSize("MT", 827, tam);
doc.DefaultPageSettings.PaperSize = ps;
doc.PrintPage += new PrintPageEventHandler(this.PagePrint);
// print the page
doc.Print();
stringToPrint.Close();
qs = "~/frmMensagem.aspx?msg=Recibo Impresso!";
HttpContext.Current.Response.Redirect(qs);
}
private void PagePrint(object sender, PrintPageEventArgs e)
{
float linesPerPage = 0;
float linePosition = 0;
int lineCount = 0;
float leftMargin = 5;
float topMargin = 5;
String line = null;
linesPerPage = altura;//e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
//linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
while (lineCount < linesPerPage && ((line = stringToPrint.ReadLine()) != null))
{
linePosition = topMargin + (lineCount * printFont.GetHeight(e.Graphics));
e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, linePosition, new StringFormat());
lineCount++;
if (true)
{
}
}
line = null;
if (line != null )
e.HasMorePages = true;
else
e.HasMorePages = false;
}
}
Hello! Take a look at this link. Maybe it will help you! dot-matrix-non-reconfigure-the-paper-size
– Kamila Gomes