Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 与Winforms类似的WPF打印_C#_Wpf_Winforms_Memory_Printing - Fatal编程技术网

C# 与Winforms类似的WPF打印

C# 与Winforms类似的WPF打印,c#,wpf,winforms,memory,printing,C#,Wpf,Winforms,Memory,Printing,下面是我在Windows窗体中进行打印的过程。 我使用了PrintDocument类。它包含PrintPage事件,我用它来绘制我需要打印的图形,并按照我的预期成功地获得了结果 代码如下: public PrintDocument Printing { m_printDocument = new PrintDocument(); m_printDocument.PrintPage += new PrintPageEventHandler(OnPrintPage); } OnPrin

下面是我在Windows窗体中进行打印的过程。 我使用了PrintDocument类。它包含PrintPage事件,我用它来绘制我需要打印的图形,并按照我的预期成功地获得了结果

代码如下:

public PrintDocument Printing
{
   m_printDocument = new PrintDocument();
   m_printDocument.PrintPage += new PrintPageEventHandler(OnPrintPage);
}
OnPrintPage的代码如下所示:

protected virtual void OnPrintPage(object sender, PrintPageEventArgs e)
 {
      //Image img = I have the things to be printing in the form of image.
      e.Graphics.DrawImage(img, new Point(0,0));
 }
在WPF中:

我正在使用固定文档,通过使用下面的代码,我可以打印

PrintDialog print = new PrintDialog();
print.PrintDocument(FixedDocument.DocumentPaginator, "Print") //Where Fixed document contains the data to be printed.
这导致内存不足,无法继续执行程序。 但我得到了一份没有任何问题的固定文件。 有什么解决办法吗。。。?
我希望WPF中也会有类似Windows窗体的东西…

当我的页面包含大量视觉元素(图形/图像/复杂的图表)时,我常常会看到这种情况。而不是一次打印完整的文档(这可能导致内存不足)

我打印了其中一页

 PrintQueue selectedPrntQueue = printDialog.PrintQueue;     
 XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(selectedPrntQueue);
 SerializerWriterCollator collator = writer.CreateVisualsCollator();
 collator.BeginBatchWrite();
 var paginator = FixedDocument.DocumentPaginator;
 FixedPage fixedPage = paginator.GetFixedPage(printedPageCount)
 ContainerVisual newPage = new ContainerVisual();
 Size sz = new Size(pageSize.Height.Value, pageSize.Width.Value);
 fixedPage.Measure(sz);
 fixedPage.Arrange(new Rect(new Point(), sz));
 fixedPage.UpdateLayout();
 newPage.Children.Add(fixedPage);
 collator.Write(newPage);
在打印了几页之后,我不得不做GC(我的神奇数字是10)。
您可能需要根据自己的需要调整此选项。

当我的页面包含大量视觉元素(图形/图像/复杂图表)时,我通常会得到此选项。而不是一次打印完整的文档(这可能导致内存不足)

我打印了其中一页

 PrintQueue selectedPrntQueue = printDialog.PrintQueue;     
 XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(selectedPrntQueue);
 SerializerWriterCollator collator = writer.CreateVisualsCollator();
 collator.BeginBatchWrite();
 var paginator = FixedDocument.DocumentPaginator;
 FixedPage fixedPage = paginator.GetFixedPage(printedPageCount)
 ContainerVisual newPage = new ContainerVisual();
 Size sz = new Size(pageSize.Height.Value, pageSize.Width.Value);
 fixedPage.Measure(sz);
 fixedPage.Arrange(new Rect(new Point(), sz));
 fixedPage.UpdateLayout();
 newPage.Children.Add(fixedPage);
 collator.Write(newPage);
在打印了几页之后,我不得不做GC(我的神奇数字是10)。
您可能需要根据需要调整此打印机。

此打印机直接打印到默认打印机。有没有办法让我选择打印机?直接打印到默认打印机。有没有办法让我选择打印机。?