How to detect that saving Excel file to PDF takes a long time and results in large file

Hi,


We found some Excel files that take a long time to convert to PDF. The Workbook contains a realy lot of columns and rows. When I save the file to PDF in Excel I get a confirmation that this may take a long time.

  1. Is there a way to get a notification or a function that will let me detect this situation with Aspose.Cells?

  2. Is there a way to monitor the process of saving the workbook to PDF and cancel it when it takes a long time? (other than having the save in a thread an kill the thread if it takes to long, what most likely will result in memory leaks)
Regards
Andreas Ruge


Hi Andreas,


Please note, a spreadsheet may take more time for the conversion (to PDF format) in case it contains more pages. Along with that, the time for the conversion process also depends on other factors such as number of objects (shapes/charts and so on) as such objects will be converted to images before becoming the part of final PDF document. Unfortunately, there isn’t a concrete method to detect if a spreadsheet is going to take long time for the conversion, however, you can get some idea by inspecting the number of pages in the spreadsheet while using the code snippet provided at the bottom of this post. Please also note that if you are trying to render one worksheet on one PDF page, it will also take more time than the normal conversion. Regarding the other part of your inquiry, I am not familiar with any Aspose.Cells’ mechanism to kill the conversion process upon some trigger. I will discuss this matter with the concerned member of the product team and share the feedback soon.

C#

var book = new Workbook(dir + “sample.xlsx”);
foreach (Worksheet sheet in book.Worksheets)
{
Console.WriteLine(sheet.Name);
var render = new SheetRender(sheet, new ImageOrPrintOptions());
Console.WriteLine(render.PageCount);
}
Hi Andreas,

a.ruge:
Is there a way to monitor the process of saving the workbook to PDF and cancel it when it takes a long time? (other than having the save in a thread an kill the thread if it takes to long, what most likely will result in memory leaks)

In reference to your original request as quoted above, Aspose.Cells APIs provide the mechanism to interrupt the process by using the Aspose.Cells.InterruptMonitor class. This mechanism needs two threads to handle the process where one thread has to be used for loading/saving Workbook and other for checking the time and interrupt the process.

Please find the attachment for the program.cs (in an archive) to check the implementation of aforementioned approach. Hopefully, it will suffice your needs.

Hi,


I think that solution will work for me, thanks for the quick responce.

Hi again,


Thank you for accepting the proposed solution. Please feel free to contact us back in case you need our further assistance with Aspose APIs.