我有一个窗口服务,它使用 PrintDocument 类打印带有图像的某些文档。有时,我在打印“传递给系统调用的数据区域太小”时遇到此错误,并且报告上的图像未打印。我一直在寻找原因。这是代码:
public string Print(List<PrintPageInfo> printList, Printer_Settings printerSettings)
{
string result = string.Empty;
try
{
List<PrintPageInfo> sortedPrintList = printList.OrderBy(p => p.SequenceOrder).ThenBy(x => x.SubSequenceOrder).ToList();
lock (_printLocker)
{
foreach (var item in sortedPrintList)
{
streams = item.Streams;
if (streams == null || streams.Count == 0)
throw new Exception("No stream to print.");
using (var printDoc = new PrintDocument())
{
printDoc.PrinterSettings.PrinterName = printerSettings.PrinterName;
//if (printDoc.PrinterSettings.IsValid) throw new Exception("Printer name is invalid.");
PrintController printController = new StandardPrintController();
printDoc.PrintController = printController;
printDoc.DefaultPageSettings.Color = true;
printDoc.DefaultPageSettings.Landscape …Run Code Online (Sandbox Code Playgroud)