PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Sep 24, 2020 4:34 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Jun 03, 2020 3:19 pm 
Offline

Joined: Wed Jun 03, 2020 3:15 pm
Posts: 2
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);
                    }


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 04, 2020 9:56 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 569
Location: CCAA
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?

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 04, 2020 11:29 am 
Offline

Joined: Wed Jun 03, 2020 3:15 pm
Posts: 2
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 04, 2020 12:51 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 569
Location: CCAA
PDFsharp is Open Source and anybody can create a port with any modification they like.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group