Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Jun 03, 2025 2:59 am

Hi,

We are encountering an issue when converting an Excel file to PDF using our licensed version of Spire.XLS 15.5.2. The process hangs indefinitely at the following line:
Code: Select all
 workbook.SaveToStream(outputStream, FileFormatXls.PDF);

Below is the relevant portion of our code:
Code: Select all
string filePath = @"C:\path\to\your\file.xlsx";
 var workbook = new Workbook();

 workbook.LoadFromFile(filePath);

 foreach (var worksheet in workbook.Worksheets)
 {
     worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
     worksheet.PageSetup.Orientation = PageOrientationType.Portrait;
     worksheet.PageSetup.PrintArea = null;
     worksheet.PageSetup.FitToPagesWide = 1;
 }

 workbook.ConverterSetting.SheetFitToWidth = true;

 using var outputStream = new MemoryStream();
 workbook.SaveToStream(outputStream, FileFormatXls.PDF);
 return outputStream.ToArray();



This issue occurs only for one particular .xlsx file. All other files work as expected. Since this file may contain sensitive data, we are not comfortable sharing it on a public forum. Is there a way to share the file privately with your support team for investigation?

Thank you,

Axima
 
Posts: 9
Joined: Wed Nov 27, 2013 12:28 am

Tue Jun 03, 2025 5:46 am

Hello,

Thanks for your inquiry.
Please send your file to my email [email protected]. We will keep your file absolutely confidential, solely for testing purposes, and will not use it for any other purpose. Thank you for your trust in our team.

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Thu Jun 05, 2025 10:07 am

Hello Axima,

Through further investigation, we found that the issue of the program running for too long is caused by this line of code (worksheet.PageSetup.PrintArea = null). If this line of code is commented out, the execution time of the program can be shortened to approximately 15 seconds.
This issue is related to the structure of your Excel document. You can try clearing the print area in Microsoft Excel. You will find that each worksheet contains a large number of columns, with an overall content of over 500 pages. I suggest you comment out this line of code to verify if the performance of the program has been improved. If you have any questions, please feel free to provide feedback.If you have any other questions, please feel free to write back.

Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Return to Spire.XLS