プリンタ(HP PageWide MFP P57750)をイーサネットケーブルでプライベートネットワークに接続しています。シンプルなC#Web Appでは、ユーザーはpdfファイルをプリンタに送信し、印刷する部数を設定します。印刷の最後に、アプリはジョブの最後に通知する必要があります。C# - 印刷の最後をキャッチできません
PrintDocumentのEndPrintイベントを使用しようとしましたが、プリンタがまだ印刷中であるため、間違った時間に起動するようです。
また、PrintJueInfoCollectionでPrintQueueを使用しようとしましたが、初めて「印刷」PrintJobStatusを返します。それから私は5秒待って、ステータスを再確認しますが、プリンタがまだ印刷している間にキューにジョブがありません!
「コントロールパネル」 - >「デバイスとプリンタ」の「ジョブの進行状況」を参照してください。印刷枚数が多く、プリンタがまだ印刷中であっても、印刷はわずか数秒間続きます。クライアントが印刷するファイルをプリンタに送信した後でジョブが削除されると思います。
印刷の実際の終わりをどうやって捉えることができますか?
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(filePath);
pdf.PrinterName = CicloStampa.Properties.Settings.Default.NomeStampante;
pdf.PrintDocument.PrinterSettings.Copies = (short)numeroCopie;
pdf.PrintDocument.Print();
PrintServer myPrintServer = new PrintServer();
PrintQueue pq = myPrintServer.GetPrintQueue(CicloStampa.Properties.Settings.Default.NomeStampante);
var printing = true;
while (printing)
{
pq.Refresh();
PrintJobInfoCollection pCollection = pq.GetPrintJobInfoCollection();
foreach (PrintSystemJobInfo job in pCollection)
{
//SpotTroubleUsingJobAttributes returns KO/OK by matching PrintJobStatus. First time returns PrintJobStatus.Priting. Second time, pCollection is empty and the printer is still printing.
var res = SpotTroubleUsingJobAttributes(job);
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Logs\LogImportazione.txt", DateTime.Now.ToString() + " ---- \t\t\t RES: " + res + "\n");
if (res.StartsWith("KO"))
{
//DO STUFF
}
else
{
//END OF PRINT
printing = false;
}
}
if (pCollection.Count() == 0)
{
printing = false;
}
if (printing)
{
System.Threading.Thread.Sleep(5000);
}
}
http://stackoverflow.com/questions/19176143/net-end-printing-event – CodeCaster