2011-01-19 90 views
5

最近、私が取り組んでいるアプリケーション(.Net 4.0、WPFフロントエンド)で印刷が遅い理由を理解しようと多くの時間を費やしました。すべてのアイデアがありません(150ページを印刷するのに25分以上)。WPFから非常に遅い印刷

私は、コントロールから直接ベクトルデータを取得する方法と、コントロール(RenderTargetBitmap)を最初にレンダリングしてイメージを送信する方法の両方で、さまざまな印刷方法(PrintDialog、XpsDocumentWriter、VisualsToXpsDocument)を試しましたが、結果。

興味深いことに、VisualsToXpsDocumentを使用してバッチ書込みを行う場合、印刷フレームワークが21ページを処理する時間内に186ページのコンテンツを作成できます。ここでは何かが間違っています。

アプリケーションの一部のコントロールの複雑さに問題がないことを確認するために、4000行の静的データと約8列のデータグリッドだけを含むスタンドアロンのデモアプリケーションを作成しました。印刷だけで、データグリッド自体にパフォーマンス上の問題はありません。私が使用してきた最も受け入れられたアプローチは、結果が悪いことです。私は、次のコードを使用している場合

 this.writer 
      = PrintQueue.CreateXpsDocumentWriter(this.SelectedPrinter.PrintQueue); 

     PrintingDocumentPaginator paginator 
      = new PrintingDocumentPaginator(this.PrintConfiguration, 
       contentSize, pageSize, contentRect, this.printSource, false); 

     this.writer.WritingProgressChanged += this.OnPrintingProgressChanged; 
     this.writer.WritingCompleted += this.OnPrintingCompleted; 
     this.writer.WritingCancelled += this.OnPrintingCanceled; 

     this.writer.WriteAsync(paginator, 
       this.PrintConfiguration.PrintTicket, paginator.PageCount); 

はまた、EndBatchWriteへの呼び出しは()はるかに長く取って印刷処理の残りの部分と、非常に迅速にヒットします。

 this.writer 
      = PrintQueue.CreateXpsDocumentWriter(this.SelectedPrinter.PrintQueue); 

     PrintingDocumentPaginator paginator 
      = new PrintingDocumentPaginator(this.PrintConfiguration, 
        contentSize, pageSize, contentRect, 
        this.printSource, this.useVectorData); 

     this.writer.WritingProgressChanged += this.OnPrintingProgressChanged; 
     this.writer.WritingCompleted += this.OnPrintingCompleted; 
     this.writer.WritingCancelled += this.OnPrintingCanceled; 

     VisualsToXpsDocument sdf 
      = (VisualsToXpsDocument)this.writer.CreateVisualsCollator(); 

     for (int i = 0; i < paginator.PageCount; i++) 
     { 
      sdf.WriteAsync(paginator.GetPageVisual(i)); 
     } 

     sdf.EndBatchWrite(); 

私はここで間違っていますか?間違ったデータをプリンタに送信していますか?私が見ていない秘密はありますか?

EDIT - これは物理プリンタだけでなく、ファイル、プリンタ、すなわちXPSプリンタに適用され、PDFなど

乾杯、

サム。

答えて

0

これは私にとって本当に速いしている、ほとんど私が何をすべきかです:

 LocalPrintServer localPrintServer = new LocalPrintServer(); 
     System.Printing.PrintQueue pq = new System.Printing.PrintQueue(localPrintServer, localPrintServer.DefaultPrintQueue.FullName); 

     System.Windows.Xps.XpsDocumentWriter docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(pq); 
     PrintCapabilities pc = pq.GetPrintCapabilities(); 

     PageImageableArea pia = pc.PageImageableArea; 

     if (docWriter != null) 
     { 
      DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator; 

      // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. 
      paginator.PageSize = new System.Windows.Size(pia.ExtentWidth, pia.ExtentHeight); 

      // Send content to the printer. 
      docWriter.Write(paginator); 
     } 

私はそれを必要としたことがないよう、使用するループを使用しないでください。私はただ手放し、後で到着するときのエラーを処理します(それは手前でプリンタの状態をチェックした後です)。プリンタのステータスを確認するには、使用しているプリンタキューのステータスプロパティを調べます。

どのような場合でも役立つことを願っています。

+0

印刷ジョブが印刷キューに表示されていますか?私は3年前にこの問題を抱えていました。特定の状況下では、ポストスクリプトに直接変換できるコンテンツを生成するのではなく、WPF印刷システムがコンテンツをラスタライズするという事実と関係していました。 –