Conversion from Excel To PDF takes long time


#1

Hello,

I am using Aspose cell .Net version 18.6.0.0. I have a excel containing 2 worksheet full of different charts (eg. Line, scatter). I have a piece of code which convert excel to PDF and return the bytes at the end to my client side.

Code Snippet:-

private byte[] convertExcelToPdf(Workbook wb)
{
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(SaveFormat.Pdf);
pdfSaveOptions.OnePagePerSheet = true;
using (MemoryStream ms = new MemoryStream())
{
wb.Save(ms, pdfSaveOptions);
ms.Seek(0, SeekOrigin.Begin);
return ms.ToArray();
}

    }

Report generation of just an excel takes 2 seconds but PDF version (conversion excel to pdf) take 5-6 seconds for a report.
I have also tried
pdfSaveOptions.ImageType = ImageFormat.Png;
but it didn’t work. Conversion time couldn’t decrease.

ASPOSE CHARTS.PNG (34.1 KB)


#2

@SPDora,

Thanks for the sample code segment, screenshot and details.

Well, I think the time cost (i.e, 5-6 seconds) for PDF conversion might be ok. Please note, for rendering PDF, each chart is rendered to image and then pasted on PDF page accordingly, so it might take a little time to convert all the charts to images. Also, since you are using the code, i.e., “pdfSaveOptions.OnePagePerSheet = true”, so this line might take a few seconds more if there are long list of charts in a sheet to be rendered on single PDF page (you may comment this line to give it a try if it makes any difference).

If you still think the PDF rendering time cost is more, then share your template file, we will check it soon.


#3

@Amjad_Sahi Thanks for the quick reply. I tried commenting that part but I found no such difference.

Before
-----------------------------------TIME ELAPSED ON watchExcelToPDF 5307-----------------------------------------

After
-----------------------------------TIME ELAPSED ON watchExcelToPDF 5047-----------------------------------------

Please see excel template consist of charts and some hidden sheets.

ASPOSE CELL TEST TEMPLATE.zip (161.8 KB)


#4

@SPDora,
We have checked this conversion on different machines and observed that it takes almost 4 seconds for this conversion. If you use Excel 365 to convert this file to PDF, even that takes time similar to Aspose.Cells. As mentioned by Amjad that it is expected behaviour and does not seem to be that long while comparing it with the time taken by Excel. Please feel free to write us back if you have any other query in this regard.


#5

There a huge performance difference in excel to pdf conversion between Windows 10 and Windows Server 2008 machine

The following code takes 3 seconds on windows 10 machine from my visual studio, but when deployed on IIS running on 2008 it takes about a minute.

Please help

Aspose.PDF 18.6.1.0
Aspose.Cells 18.6.0.0

public byte[] GetPDFBytes(Workbook workbook)
{
if (workbook != null)
{
using (MemoryStream ms = new MemoryStream())
{
// For a two page excelll with charts the following line takes 3 secs on Windows 10
// but on Windows server 2008 (IIS 7.5) takes 56 seconds
workbook.Save(ms, new PdfSaveOptions(SaveFormat.Pdf) { OnePagePerSheet = true });

                ms.Seek(0, SeekOrigin.Begin);
                return ms.ToArray();
            }
        }

        return null;
    }

#6

@SPDora,

I would recommend you to try using latest versions of Aspose.Cells if it makes any difference. By the way, I do not think your issue (“IIS running on 2008 it takes about a minute”) has any links to Aspose.Cells as it is a .NET library for creating and rendering MS Excel files and it does not do any specific/separate process when working on desktop or web scenarios. The APIs should equally work seemlessly on both windows and web applications. We recommend you should browse internet and check related forums to debug and sort out your issue accordingly. For example, see some sample threads for your reference:
https://forums.iis.net/t/1235429.aspx?Slow+performance+on+IIS
https://forums.iis.net/t/1173696.aspx?Slow+IIS+7+5+performance

Hope, this helps a bit.


#7

It doesn’t look like an IIS issue. It is not an IIS first request issue either.
I don’t see any issue from the IIS counters perspective either.

If try to save the Aspose Workbook as Xlsx the performance is same on both my local machine and the server. (It is done in 3 to 4 seconds)

The issue occurs when I try to save the Workbook as pdf or XPS.
On the server when I try to save Aspose workbook as pdf or XPS, the process takes 98 to 100% of the cpu for almost a minute but on local machine the cpu usage is below 10% and the process takes only 4 seconds.

Is it because of any missing fonts or some other resources that Aspose is using for conversion ?

The is the piece of code I am using

var ms = new MemoryStream();
wb.Save(ms, SaveFormat.Pdf);

Thanks


#8

@SPDora,

Yes, it might be the case. Please make sure that all the underlying fonts (used in the workbook, e.g calibri, etc.) should be installed on the server. The fonts folder should be accessible seamlessly by the application. It is quite possible, Aspose.Cells has to traverse the directories and could not find the underlying fonts (.ttf files) and has to replace with matching fonts (present in the current fonts directory), the process might take time. See the document for your reference.
https://docs.aspose.com/display/cellsnet/Configuring+Fonts+for+Rendering+Spreadsheets


#9

The two fonts that are used in excel are Calibri and Arial and both the fonts are available on the server. I did the following code change to see if there is any warnings and I am not getting any on neither the server nor on the dev machine.

This is happens only for pdf and xps. if I save it as xlsx it the performance is same on both dev and server.
Do you have any other suggestions

Thanks

public void saveToPdf(Workbook wb)
    {
        IWarningCallback warningHandler = new MyWarningCallback();
        var pdfSaveOptions = new PdfSaveOptions(SaveFormat.Pdf)
        {
            OnePagePerSheet = true,
            WarningCallback = warningHandler
        };

        using (var ms = new MemoryStream()) { 
            // This line takes 50 seconds on the server while it takes only 4 seconds in the local machine
            wb.Save(ms, pdfSaveOptions);
        }
    }

public class MyWarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        System.Diagnostics.Debug.Print("WarningCallback INFO:  {0}: {1}" + info.WarningType, info.Description);
    }
}

#10

@SPDora,

Did you try using our latest version/fix: Aspose.Cells for .NET v19.8 and how it goes?


#11

@SPDora,
Please also share the generated PDF files on your dev and server machine for our reference.