我通过使用 PDFiumSharp 将每一页转换为 PNG 图像来打印 PDF 文件。接下来,我将此图像绘制到 Graphics。
private void PrintPage(object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawImage(images[pageNum], ev.Graphics.VisibleClipBounds);
pageNum++;
if (pageNum == images.Count)
{
ev.HasMorePages = false;
}
else
{
ev.HasMorePages = true;
}
}
public void Print()
{
printDocument.PrintPage += new PrintPageEventHandler(PrintPage);
pageNum = 0;
if (printDocument.PrinterSettings.IsValid)
{
printDocument.Print();
}
else
{
throw new Exception("Printer is invalid.");
}
}
问题是打印机接收的数据非常大,整个过程运行缓慢。我尝试lpr
在 Windows 上使用命令。它直接适用于 PDF 文件,但我的应用程序需要支持双面打印、不同纸张来源等,而lpr
.
如何在不转换为图像的情况下使用 System.Drawing.Printig(或其他提供类似功能的东西)打印 PDF?我使用 .NET Core 3.1,我的应用程序应该是跨平台的。