I'm printing PDF files by converting every page to PNG image with PDFiumSharp. Next, I draw this image to 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.");
}
}
The problem is that printer receives very large data and the whole process works slowly. I tried to use lpr command on Windows. It works directly with PDF files, but my application is required to support duplex, different paper source, etc. which is unavailable in lpr.
How can I print PDF using System.Drawing.Printig (or something other what offers similar functionalities) without conversion to image? I use .NET Core 3.1, my application should be cross-platform.