Aspose.Cells C++ has segmentation fault on second save as pdf

We are currently trying to save an imported workbook as a PDF. The first attempt is successful, but the second results in a segmentation fault. In short, the lines are

Aspose::Cells::Startup();
Workbook wb = Aspose::Cells::Workbook(fileName);

// Option 1: Save as fileName with .pdf suffix
wb.save(fileName);
// Option 2: Save with pdfSaveOptions
Aspose::Cells::PdfSaveOptions saveOptions;
wb.Save(fileName, saveOptions);
// Option 3: Save with SaveFormat
wb.Save(fileName, Aspose::Cells::SaveFormat::Pdf);

wb.Dispose();
Aspose::Cells::Cleanup();

No matter which variant we use, the second call to the Save function results in a segmentation fault. Are we missing a cleanup function that needs to be called after the first save, or is there something inherently wrong with our method? We weren’t able to find any more information in the API document. Thank you for your help!

@Georg_Hofmeister_BGZ,

Does the issue occur only with your specific Excel file? If possible, kindly compress the file into a zip format and attach the zipped archive here. We will look into it soon.

@amjad.sahi,

thank your for comming back at me. Well, I thought I remembered that happening with any Excel file, even an empty one - but when I checked now, an empty file did work. I was able to boil it down to… well, any type of image in the document, be it a png or an svg. I created this beautiful MWE (101,3 KB) for you. It is nothing but a plain new Excel sheet with a random png I had at hand. Using this file, the described behavior is observable.

If there are any followup questions, please do not hesitate to ask!

@Georg_Hofmeister_BGZ,

Which version of Aspose.Cells for C++ you are using? I tested your scenario/case using your template XLSX file with Aspose.Cells for C++ 25.7.0 using the following sample code, it works fine and I do not get any exception/error. The output PDF files (attached) are fine tuned.

Aspose::Cells::Startup();
// directory path
U16String outDir(u"e:\\test2\\");

// Path of input excel file
U16String fileName = outDir + u"Mangelmeldung.xlsx";

// Path of output PDF file1
U16String outfileNamePDF1 = outDir + u"1.pdf";

// Path of output PDF file2
U16String outfileNamePDF2 = outDir + u"2.pdf";

// Path of output PDF file2
U16String outfileNamePDF3 = outDir + u"3.pdf";

Workbook wb = Aspose::Cells::Workbook(fileName);

// Option 1: Save as fileName with .pdf suffix
wb.Save(outfileNamePDF1);

// Option 2: Save with pdfSaveOptions
Aspose::Cells::PdfSaveOptions saveOptions;
wb.Save(outfileNamePDF2, saveOptions);

// Option 3: Save with SaveFormat
wb.Save(outfileNamePDF3, Aspose::Cells::SaveFormat::Pdf);

wb.Dispose();
Aspose::Cells::Cleanup();

1.pdf (57.1 KB)
2.pdf (57.1 KB)
3.pdf (57.1 KB)

Please try using Aspose.Cells for C++ 25.7.0. Let us know with details if you still find the issue.

Thank you for your response. We are using Aspose.Cells for C++ 25.7.0.

From reading your code, I found that we are not talking about the same issue. However, I was able to fix our issue. We had a routine which did something like

Aspose::Cells::Startup()

// load wb, print pdf, dispose wb

Aspose::Cells::Dispose()

for every workbook. Repeatedly calling those methods does not lead to a runtime error, but a SIGSEV under the aforementioned conditions. Calling print repeatedly indeed did not result in any issues.

However, the resulting PDF does not respect the margins provided in the page settings, so that the printout looks different than what I receive from Excel PDF export. I sometimes get wrong color shades (a deeper blue than I expect) and wrong page margins. Please check the following archive (9,0 KB) containing a relatively empty xlsx file and the pdf output of aspose and excel. Do you have any idea how to solve that?

@Georg_Hofmeister_BGZ,

I again tested using your new XLSX file “Test.xlsx” to convert to PDF with the following sample code, it works fine and as expected. I do not get any issue with margins or page settings in the output PDFs.

Aspose::Cells::Startup();

// Output directory path
U16String outDir(u"e:\\test2\\");

// Path of output excel file
U16String fileName = outDir + u"Test.xlsx";

// Path of output PDF file1
U16String outfileNamePDF1 = outDir + u"1.pdf";

// Path of output PDF file2
U16String outfileNamePDF2 = outDir + u"2.pdf";

// Path of output PDF file2
U16String outfileNamePDF3 = outDir + u"3.pdf";

Workbook wb = Aspose::Cells::Workbook(fileName);

// Option 1: Save as fileName with .pdf suffix
wb.Save(outfileNamePDF1);
// Option 2: Save with pdfSaveOptions
Aspose::Cells::PdfSaveOptions saveOptions;
wb.Save(outfileNamePDF2, saveOptions);
// Option 3: Save with SaveFormat
wb.Save(outfileNamePDF3, Aspose::Cells::SaveFormat::Pdf);

wb.Dispose();

Aspose::Cells::Cleanup(); 

1.pdf (19.7 KB)
2.pdf (19.7 KB)
3.pdf (19.7 KB)

Please find attached the output PDFs in the zipped archive, all three files are Ok.

Could you please create a standalone VS.NET sample app (complete source code and resource files without compilation errors), upload to some file sharing service (e.g., Dropbox, Google drive, etc.) and share the Download link here to get the project (we should not require to enter credentials) seamlessly. We will check your issue soon. Also, share your complete environment details.