Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Sep 03, 2021 4:36 am

Hi there,

I'm having an issue with using FreeSpire.PDF.

I have the following snippet of code: (part of a conversion from tiff to pdf)

Code: Select all
image.SelectActiveFrame(FrameDimension.Page, pageIndex);
using var currentImage = new MemoryStream();

image.Save(currentImage, ImageFormat.Bmp);

var img = PdfImage.FromStream(currentImage);
var orientation = img.Width > img.Height
    ? PdfPageOrientation.Landscape
    : PdfPageOrientation.Portrait;
var page = doc.Pages.Add(SizeF.Empty, new PdfMargins(0), PdfPageRotateAngle.RotateAngle0, orientation);
var sw = Stopwatch.StartNew();
page.Canvas.DrawImage(img, 0, 0, page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height);
Console.WriteLine("Took {0} to Draw Image", sw.Elapsed);


When I use this on my windows development pc, it works great,
The tiff files are scans, so they are meant to be drawn full size on each page.
It produces a small pdf, with the tiff files correctly placed.

However, when I build for linux (target framework is net5.0), and run it there, it also produces the same file, but it is a lot slower.

On windows the console output is: Took 00:00:00.0827767 to Draw Image
But on linux it is: Took 00:00:01.9174227 to Draw Image

So instead of 80 milliseconds, it takes almost 2 seconds!

While writing this post, I think the issue is in libgdiplus on linux.
Do you have any idea on how to speed this up?

Thanks, Erik

erik.vandergaag
 
Posts: 2
Joined: Fri Sep 03, 2021 3:57 am

Fri Sep 03, 2021 10:11 am

Hello,

Thank you for your inquiry.
I simulated a tiff file to test and found that the time spent on Windows and Linux are around 80 and 120 milliseconds respectively. The underlying elements used to draw pictures in Windows and Linux are inconsistent, hence the time difference is normal on different system. For your case, please provide the following information to help us further investigate whether the time can be optimized. You could attach them here or send them to us via email([email protected]). Thanks in advance.
1) Your tiff file.
2) Your full test code.
3) Your Linux environment, such as CentOS 7.5.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Sep 03, 2021 11:32 am

Hi,

Attached is a test project which shows the issue, which includes a tiff file.

I noticed now also that the pdf file created under linux is also somewhat larger in size than when created in Windows.

I am testing on Ubuntu 16.04.4 Server that is virtual, however, the final destination for the app will be on Ubuntu 18 or 20.

For the application to work on linux, I had to install libgdiplus.

Thanks,
Erik

erik.vandergaag
 
Posts: 2
Joined: Fri Sep 03, 2021 3:57 am

Mon Sep 06, 2021 8:23 am

Hello,

Thank you for sharing and sorry for the late reply as weekend.
I tested your project and found that it took more time (almost 2 seconds) when running on Linux, and the file generated on Linux is about twice as large as it generated on Windows. I have logged the two behaviors into our bug tracking system with the ticket number SPIREPDF-4624. If there is any optimization, I will inform you. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF