private void button1_Click(object sender, EventArgs e)
{
ttime = DateTime.Now.ToString("dd-MM-yyyy");
string folderName = @"c:\PRN File";
@System.IO.Directory.CreateDirectory(folderName);
String path = @"c:\PRN File\myFile.prn";
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
{
using (TextWriter tw = new StreamWriter(fs))
{
tw.WriteLine("<xpml><page quantity='0' pitch='76.2 mm'></xpml>SIZE 76.2 mm, 76.2 mm");
tw.WriteLine("DIRECTION 0,0");
tw.WriteLine("REFERENCE 0,0");
tw.WriteLine("OFFSET 0 mm");
tw.WriteLine("SET PEEL OFF");
tw.WriteLine("SET CUTTER OFF");
tw.WriteLine("<xpml></page></xpml><xpml><page quantity='1' pitch='76.2 mm'></xpml>SET TEAR ON");
tw.WriteLine("CLS");
tw.WriteLine("CODEPAGE 1252");
tw.WriteLine("TEXT 579,370,\"ROMAN.TTF\";,180,1,12,\"Party Name:\"");
tw.WriteLine("BARCODE 527,546,\"128M\",102,0,180,3,6,\"!104CR!0991234567890123445\"");
tw.WriteLine("TEXT 451,439,\"ROMAN.TTF\",180,1,12,\"CR1234567890123445\"");
tw.WriteLine("TEXT 579,329,\"ROMAN.TTF\",180,1,12,\"Order no:\"");
tw.WriteLine("TEXT 579,289,\"ROMAN.TTF\",180,1,12,\"Ref No:\"");
tw.WriteLine("TEXT 579,249,\"0\",180,13,10,\"Date:\"");
tw.WriteLine("TEXT 579,209,\"ROMAN.TTF\",180,1,12,\"W X H:\"");
tw.WriteLine("TEXT 579,169,\"ROMAN.TTF\",180,1,12,\"Prd Ty:\"");
tw.WriteLine("TEXT 579,128,\"ROMAN.TTF\",180,1,12,\"Remarks:\"");
tw.WriteLine("TEXT 392,370,\"ROMAN.TTF\",180,1,12,\"AMI Distributors\"");
tw.WriteLine("TEXT 439,329,\"ROMAN.TTF\",180,1,12,\"" + order_no + "\"");
tw.WriteLine("TEXT 460,289,\"ROMAN.TTF\",180,1,12,\"" + o_ref + "\"");
tw.WriteLine("TEXT 497,249,\"0\",180,13,10,\"" + ttime + "\"");
tw.WriteLine("TEXT 477,209,\"ROMAN.TTF\",180,1,12,\"" + w + "" + u + " X " + h + "" + u + "\"");
tw.WriteLine("TEXT 472,169,\"ROMAN.TTF\",180,1,12,\"" + pro + "\"");
tw.WriteLine("TEXT 436,128,\"ROMAN.TTF\",180,1,12,\"" + oprating + "\"");
tw.WriteLine("PRINT 1,1");
tw.WriteLine("<xpml></page></xpml><xpml><end/></xpml>");
}
}
Process proc = null;
try
{
string batDir = string.Format(@"c:\PRN File\");
proc = new Process();
proc.StartInfo.WorkingDirectory = batDir;
proc.StartInfo.FileName = "a.bat";
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
MessageBox.Show("File Print Success");
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
}
}
a.bat文件中的: 复制myFile.prn LPT1
myFile.prn我不打印此文件,myFile.prn也在同一目录中
当我正确运行bat文件打印,但是使用打印按钮上的窗口点击没有任何反应。
我不知道这个问题我的c驱动器不允许我运行文件或其他