We're using PDFSharp in a .NET Core 3.1 application and on Windows it takes .5 sec to convert a 20 page TIF to a PDF, but on Linux it takes about 20seconds. Looks like the DrawImage is what takes the lions share of the time. Any ideas? Here's the code.
Code:
await using MemoryStream ms = new MemoryStream(ImageResources.BillImage);
_logger.LogInformation("Read stream in {ms}", sw.ElapsedMilliseconds);
sw.Restart();
using (Image img2 = Image.FromStream(ms))
{
_logger.LogInformation("FromStream in {ms}", sw.ElapsedMilliseconds);
sw.Restart();
Guid objGuid = img2.FrameDimensionsList[0];
FrameDimension objDimension = new FrameDimension(objGuid);
int pageCount = img2.GetFrameCount(objDimension);
pageCount--;
_logger.LogInformation("Get FrameCount in {ms}", sw.ElapsedMilliseconds);
sw.Restart();
for (int i = 0; i <= pageCount; i++)
{
PdfPage page = doc.AddPage();
XGraphics xgr = XGraphics.FromPdfPage(page);
img2.SelectActiveFrame(objDimension, i);
_logger.LogInformation("Processing 1 page {i} {ms}", i, sw.ElapsedMilliseconds);
sw.Restart();
XImage img = XImage.FromGdiPlusImage(img2);
_logger.LogInformation("Processing 2 page {i} {ms}", i, sw.ElapsedMilliseconds);
sw.Restart();
page.Width = img.PointWidth;
page.Height = img.PointHeight;
xgr.DrawImage(img, 0, 0);
_logger.LogInformation("Processing 3 page {i} {ms}", i, sw.ElapsedMilliseconds);
sw.Restart();
}
}
await using (MemoryStream stream = new MemoryStream())
{
doc.Save(stream, false);
var bytes = stream.ToArray();
result = Convert.ToBase64String(bytes);
}