We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Excel to PDF conversion - Page Size issue and run macros in .NET

In Short, I start the conversion by doing this :

Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions();
pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
pdfSaveOptions.EmbedStandardWindowsFonts = true;
pdfSaveOptions.DefaultFont = “Arial”;

My excel workbook is then saved to pdf like this :

                    ReportAspose.Save(_AsposeExcel + ".pdf", pdfSaveOptions);   

The Excel’s page setup is set as A3 Rotated, yet the PDF is always A4

How do I get the PDF to be the same page size as the XLS ?

(I have attached the XLS in question)
P2F_PlatHond.zip (213.4 KB)

Question 2 :

I have multiple macros in the XLS itself which I would like to run before I create the PDF. How do I do this ?

I have opened your template file in MS Excel and observed that in the print preview it has 40 pages and same pages are printed in the PDF. This page size is not A3. I have modified your page size to A3 in MS Excel and saved it. This modified file is used with the following sample code and it creates PDF file with the same A3 size.

string inputPath = "P2F_PlatHond_A3.xlsm";
// Load excel file containing some data
Workbook workbook = new Workbook(inputPath);

// Create an instance of PdfSaveOptions and pass SaveFormat to the constructor
Aspose.Cells.PdfSaveOptions pdfSaveOpt = new Aspose.Cells.PdfSaveOptions();

pdfSaveOpt.Compliance = PdfCompliance.PdfA1b;
pdfSaveOpt.EmbedStandardWindowsFonts = true;
pdfSaveOpt.DefaultFont = "Arial";

// Save the workbook to PDF format while passing the object of PdfSaveOptions
workbook.Save("outFile_A3.pdf", pdfSaveOpt);

P2F_PlatHond_A3.xlsm.zip (250.4 KB)
outFile_A3.pdf.zip (230.5 KB)


Thank you for the paper size, there must be some process somewhere in between where I create it correctly and where the actual coversion happens. I will try to hunt it down.

You did not reply to my second question : can I run macros on the spreadsheet before converting it to PDF ?

Please note that Aspose.Cells does not support executing the Macros. However you can access and modify the macros if required. Please refer to the following document for more details:

Workbook VBA Project

Hi Ashan,

So I detected the problem with A3 - I Save the XLSM with no data in (as a template). There is a process where the following happens to populate the hidden tabs with the data :

ReportAspose = new Aspose.Cells.Workbook(_AsposeExcel); // load the workbook from the XLSM
NOTE : at this point in time the page Size is A4 and not A3 as I selected !
At this point in time I can still open the XLSM in Excel and it shows it is still A3.

// Here is code which puts the data on the hidden sheets
// There is no formatting happening here, but certain rows / columns might be hidden depending on the situation

Finally this is how the data is saved :

                    ReportAspose.Settings.CreateCalcChain = false;
                    ReportAspose.Save(_AsposeExcel, SaveFormat.Auto);

When you then open the XLSM again, the page is set to A4 instead of keeping the A3.

If this is a bug in Aspose, is there any workaround I can do to get around it ?


I am afraid that I could not reproduce this issue here using the following sample code. The page size remains A3 before and after saving the file. You may please share your runnable simplified solution along with the template files that can be used to reproduce this issue. We will observe the issue here and share our feedback accordingly.

String _AsposeExcel = "MSExcelA3.xlsm";
Workbook ReportAspose = new Workbook(_AsposeExcel);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = ReportAspose.Worksheets[0];

PageSetup pageSetup = worksheet.PageSetup;
ReportAspose.Settings.CreateCalcChain = false;
ReportAspose.Save("output.xlsm", SaveFormat.Auto);

MSExcelA3.xlsm.zip (6.4 KB)
output.xlsm.zip (7.0 KB)