C# PrintDocument调用针式打印机没有反应,调用普通打印机可以打出来, 求高手指点!!!
十万火急, 客户催得我想跳楼
这是我的打印代码
public PrintDocument pdDocument;
public PageSetupDialog dlgPageSetup;
public PrintPreviewDialog ppd;
public PrintDialog pd;
private string[] lines;
public string[] Lines
{
get
{
if (ViewState["Lines"] != null)
return ViewState["Lines"] as string[];
return null;
}
set
{
lines = value;
ViewState["Lines"] = lines;
}
}
public PrintHelper()
{
pdDocument = new PrintDocument();
dlgPageSetup = new PageSetupDialog();
ppd = new PrintPreviewDialog();
pd = new PrintDialog();
dlgPageSetup.Document = pdDocument;
pd.Document = pdDocument;
ppd.Document = pdDocument;
pdDocument.PrintPage += new PrintPageEventHandler(pdDocument_PrintPage);
pdDocument.BeginPrint += new PrintEventHandler(pdDocument_BeginPrint);
pdDocument.EndPrint += new PrintEventHandler(pdDocument_EndPrint);
}
void pdDocument_EndPrint(object sender, PrintEventArgs e)
{
lines = null;
}
void pdDocument_BeginPrint(object sender, PrintEventArgs e)
{
}
/// <summary>
/// 开始打印
/// </summary>
public void Print()
{
try
{
pdDocument.Print();
}
catch (InvalidPrinterException ex)
{
File.WriteAllText("c://test.txt", ex.Message, Encoding.UTF8);
}
}
void pdDocument_PrintPage(object sender, PrintPageEventArgs e)
{
int x = 20;
int y = 20;
int count = 0;
while (count < Lines.Length)
{
e.Graphics.DrawString(Lines[count], new Font("微软雅黑", 20), System.Drawing.Brushes.Black, x, y);
y += 50;
count++;
}
count = 0;
e.HasMorePages = false;
}