PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Saving PDF in Linux takes 40x longer
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4140
Page 1 of 1

Author:  JMW [ Wed Jun 03, 2020 3:19 pm ]
Post subject:  Saving PDF in Linux takes 40x longer

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);
                    }

Author:  TH-Soft [ Thu Jun 04, 2020 9:56 am ]
Post subject:  Re: Saving PDF in Linux takes 40x longer

JMW wrote:
We're using PDFSharp in a .NET Core 3.1 application [...]
There are no "official" packages for .NET Core yet. Which version of PDFsharp are you using?

Author:  JMW [ Thu Jun 04, 2020 11:29 am ]
Post subject:  Re: Saving PDF in Linux takes 40x longer

Thanks for the reply. If it's not "official" we'll try something else. Fwiw, we were on PdfSharpNetStandard 0.0.14. Also on Windows the 20 page TIFF was 946K PDF and the one created on Linux was 2066K. Zooming all the way in on Acrobat, they looked identical.

Author:  TH-Soft [ Thu Jun 04, 2020 12:51 pm ]
Post subject:  Re: Saving PDF in Linux takes 40x longer

PDFsharp is Open Source and anybody can create a port with any modification they like.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/