1
How do I print my tickets to a matrix printer (LX300) from routines made in WPF C#? Do you have anything specific for this? A drive or plugin?
1
How do I print my tickets to a matrix printer (LX300) from routines made in WPF C#? Do you have anything specific for this? A drive or plugin?
1
Option 1= Assemble a text file, and send it to the printer, copying the file to it. Ex:
in the C#:
File.Copy("arquivo.txt","\\servidor\lx300");
or
File.Copy("arquivo.txt","lpt1");
Option 2= Use a report generator, Crystal, report Viewer, among others, and send to printer normally, by windows spooler.
Option 3=
Manages a PrintDocument and send to printer, for a PrintDialog. Follows code commented:
//Fila de linhas que devem ser impressas
Queue<string> filaLinhas = new Queue<string>();
PrintDocument p = new PrintDocument();
//Evento PrintPage do PrintDocument
p.PrintPage += delegate(object sender1, PrintPageEventArgs ev)
{
//Define a fonte utilizada para impressão
Font printFont = new Font("Consolas", 11);
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
//Calcular o número de linhas por página
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
//Imprime cada linha da página
while (count < linesPerPage && filaLinhas.Count >0 )
{
line = filaLinhas.Dequeue();
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black, 0, yPos, new StringFormat());
count++;
}
//Se existir mais linhas, gera outra página
if (line != null && filaLinhas.Count >0)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
};
//Exibe o dialogo de impressão (se não for necessário, só pular o ShowDialog e chamar o .Print(); (Lembre-se de definir a impressora, ou será utilizada a padrão do windows)
PrintDialog diag = new PrintDialog();
diag.Document = p;
diag.PrinterSettings.PrinterName = "LX 300";
if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
p.Print();
}
Browser other questions tagged c# wpf
You are not signed in. Login or sign up in order to post.
My problem, Rovan, is that I don’t have a printer for testing and my client is 250 miles from where I am. I go in it just to install what I have to install. I want to leave the printing for the end, but I need to know how to do. Remembering that WPF use for these projects. Does this code run on WPF? I have not tested yet, due to problem here, but while solving, I will test the code only, whether compile or not. This code looks windows form.
– pnet
Install a virtual printer, windows already comes with XPS and you can install a PDF for example, in such cases, will ask to save the print file, but it is good to do tests. Even using WPF, you can use the
System.Windows.Formscontaining thePrintDialogand I believe I have an equivalent (in WPF). ThePrintDocumentbelongs to theSystem.Drawing.Printingthen I believe I’m already available.– Rovann Linhalis
Okay, I’ll do that and having the result, put it to everyone.
– pnet
Some progress @pnet ?
– Rovann Linhalis
Rovann, I made a stop, because I need to finish two methods that make the calculation of the cereals (Soy and Corn) and then yes, I will take a firm impression, because what will be printed is the result of this calculation. I need it printed sometime this week.
– pnet