我有這個要求,我必須從Web應用程序打印收據。我已經找到了獲取字符串中的數據,生成臨時文本文件,將其發送到打印機並刪除文件的方法。除了打印部分,一切都很好,它什麼都不產生,一個白色的文檔!我在發送打印文件之前檢查了我的臨時文件,這裏有數據,也許我以錯誤的方式發送文件或忘記添加一個PrintPageEventHandler
(我不太確定這最後一個,或者我可能是我只是不知道)。發送文件到打印機,什麼都不打印
這就是我所做的:
private void printTextfile(String strFileName)
{
//there is this standar that makes programmers declare variables at the
//beginning of the method and this "obj" and "str" things...
PrintDocument objPrintDocument =null;
String strPrinterName = string.Empty;
//getting the printer name from web.config
strPrinterName= ConfigurationManager.AppSettings["NOMBRE_IMPRESORA"];
objPrintDocument = new PrintDocument();
objPrintDocument.PrinterSettings.PrinterName = strPrinterName;
//the temp text file created and with data
objPrintDocument.DocumentName = strFileName;
//I guess don't need this because I've setted up the file name (it is reachable)
//objPrintDocument.PrintPage += new PrintPageEventHandler(this.printTextFileHandler);
//send the file to the printer (this works)
objPrintDocument.Print();
//ok, now I've check my physic file and it has nothing in it!
}
請告訴我,如果有另一種方式來做到這一點,我只需要看到打印的數據。注意:我沒有使用白色的forecolor或類似的東西,打印機可以接收1MB的文本,只需打印1頁就沒有任何內容。
..? – MethodMan 2012-07-23 19:34:47
將數據發送到打印機的代碼在哪裏?您正在設置DocumentName,然後調用Print,但這不會打印任何內容。 – Steve 2012-07-23 19:38:32
@DJKRAZE沒有錯誤,否則打印機無法打印任何文件。 – 2012-07-23 19:58:31