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!
}
別の方法があれば教えてください。印刷されたデータを確認するだけです。注: 私は白い前景色などを使用していません。プリンターは 1 MB のテキストを受け取り、1 ページを何も含まずに印刷することができます。