Remove unwanted whitespaces and shift second sheet contents to move up - Repeat header row in subsequent pages - Excel to PDF and PDF API

I have multiple grids inside PDF file. For example, if single grid details exceeds more than one page, at that time I need to show grid header in subsequent pages as well. I am using Aspose Cells product and also I am converting the Excel file to PDF format. I have opened a thread in Aspose forum already. Please refer below link.

I am able to achieve repeat header in multiple pages in PDF file by following your approach. I have attached PDF file and sample solution for your reference. I have created two tables and placed in two different worksheets. We have procured license for Aspose PDF as well. Is it possible to place part of second table contents in 3rd page itself instead of starting from 4th page in attached PDF file because first table contents are completed in 3rd page mid way and also we are having empty space in 3rd page by Aspose PDF API? (5.8 MB)
SamplePDFReport.pdf (91.1 KB)


Thanks for contacting support.

Aspose.PDF for .NET allows you to perform different operations on PDF Pages which includes:

Concerning to the requirement of shifting page content backward to fill empty space, we are afraid that such functionality is not supported yet. However, we have logged a feature request as PDFNET-48809 in our issue tracking system for the sake of implementation. We will definitely investigate the feasibility of required feature and keep you posted with the status of its availability. Please be patient and spare us some time.

We are sorry for the inconvenience.


I have used below code to format numbers in Excel file by using Aspose Cells API. Could you please help me to format numbers in cell in PDF file by using Aspose PDF API and to setup print options for PDF file?

Number Format:

Aspose.Cells.Range range = worksheet.Cells.CreateRange(0, 0, 10, 17);
                style = workbook.CreateStyle();
                style.Custom = "#,##0;[Red](#,##0);-";
                range.ApplyStyle(style, new StyleFlag() { NumberFormat = true });

int index = worksheet.ConditionalFormattings.Add();
            FormatConditionCollection fcs = worksheet.ConditionalFormattings[index];
            CellArea ca = new CellArea();
            ca.StartRow = 0;
            ca.EndRow = worksheet.Cells.MaxRow + 1;
            ca.StartColumn = 0;
            ca.EndColumn = worksheet.Cells.MaxColumn + 1;
            int conditionIndex1 = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Equal, "0", null);
            FormatCondition fcReport = fcs[conditionIndex1];
            fcReport.Style.HorizontalAlignment = TextAlignmentType.Center;

**Print Page Setup:**

activeWorkSheet.PageSetup.FitToPagesWide = 1;
            activeWorkSheet.PageSetup.FitToPagesTall = 0;
            activeWorkSheet.Zoom = 80;
            if (isLetter)
                activeWorkSheet.PageSetup.PaperSize = PaperSizeType.PaperLetter;
                activeWorkSheet.PageSetup.PaperSize = PaperSizeType.PaperLegal;
            activeWorkSheet.PageSetup.FooterMargin = 0.3;
            activeWorkSheet.PageSetup.HeaderMargin = 0.3;
            activeWorkSheet.PageSetup.LeftMarginInch = 0;
            activeWorkSheet.PageSetup.RightMarginInch = 0.050;
            activeWorkSheet.PageSetup.TopMarginInch = 0.2;
            activeWorkSheet.PageSetup.BottomMargin = 0.2;
            activeWorkSheet.PageSetup.HeaderMarginInch = 0.0;
            activeWorkSheet.PageSetup.FooterMarginInch = 0.0;
            activeWorkSheet.PageSetup.CenterHorizontally = true;
            activeWorkSheet.PageSetup.CenterVertically = false;
            //activeWorkSheet.IsGridlinesVisible = false;
            activeWorkSheet.PageSetup.Orientation = PageOrientationType.Landscape;

**PDF Code:**

Document doc = new Document();
Page page = doc.Pages.Add();
Aspose.Pdf.Table pdfTable = new Aspose.Pdf.Table();
pdfTable.ColumnWidths = "80 175 80";
pdfTable.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.01F);
TextState tinfo = new TextState();
tinfo.Font = FontRepository.FindFont("Cambria");
tinfo.FontSize = 12;
pdfTable.DefaultCellTextState = tinfo;
pdfTable.RepeatingRowsCount = 1;
Aspose.Pdf.Row row;
row = pdfTable.Rows.Add();
Aspose.Pdf.Cell cell;
tinfo = new TextState();
tinfo.Font = FontRepository.FindFont("Cambria");
tinfo.FontSize = 12;
tinfo.FontStyle = FontStyles.Bold;
row.DefaultCellTextState = tinfo;
row.BackgroundColor = Aspose.Pdf.Color.FromArgb(226, 239, 218);
row.Cells.Add("Employee Name");
row.Cells.Add("Basic Pay");
row.Cells.Add("Total Salary");
for (int i = 0; i < iEmployeesCount; i++)
	row = pdfTable.Rows.Add();
	cell = row.Cells.Add(employees[i].BasicPay.ToString());
	cell.Alignment = HorizontalAlignment.Right;
	cell = row.Cells.Add(employees[i].TotalSalary.ToString());
	cell.Alignment = HorizontalAlignment.Right;


Please provide reply for my queries.


We apologize for the delayed response.

In order to print PDF documents and specify different printing options, you can please try using and modifying following sample code snippet:

Facades.PdfViewer viewer = new Facades.PdfViewer();
// Open input PDF file

Console.WriteLine("[Printing" + f);

// Set attributes for printing
viewer.AutoResize = false;         // Print the file with adjusted size
viewer.AutoRotate = false;         // Print the file with adjusted rotation
viewer.PrintPageDialog = false;   // Do not produce the page number dialog when printing

// Create objects for printer and page settings and PrintDocument
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();
ps.PrinterName = "Microsoft Print to PDF";

// Set printer name
ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

// Set PageSize (if required)
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

// Set PageMargins (if required)
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

// Print document using printer and page settings
ps.Copies = 1;
viewer.PrintDocumentWithSettings(pgs, ps);

Regarding Number Format, would you kindly share the output Excel file for our reference which was generated using above code snippet. We will try to generated similar output in PDF using Aspose.PDF and share our feedback with you.


I have attached sample Excel report with number formatting. Please provide solution to implement number formatting on PDF by using Aspose PDF API. (9.8 KB)


You can add values in number formats by using C# method ToString("#,##0"). Please check following code snippet in order to add table and number formats in its cells:

var doc = new Document();
var page = doc.Pages.Add();
page.PageInfo.Width = PageSize.PageLetter.Width;
page.PageInfo.Height = PageSize.PageLetter.Height;
page.PageInfo.Margin = new MarginInfo(27, 47, 27, 27);

// Instantiate a table object
var mytable = new Aspose.Pdf.Table();
mytable.DefaultCellBorder = new BorderInfo(BorderSide.All, Color.Black);
mytable.IsBordersIncluded = true;
mytable.DefaultCellPadding = new MarginInfo(5, 1, 5, 1);

var headerRow = mytable.Rows.Add();
var firstspan = headerRow.Cells.Add("Header cell 1");
firstspan.BackgroundColor = Color.Red;
var secondspan = headerRow.Cells.Add("Header cell 2");
headerRow.Cells.Add("Header cell 3");
secondspan.BackgroundColor = Color.LightBlue;

for (var i = 1; i <= 20; ++i)
 var dataRow = mytable.Rows.Add();

doc.Save(dataDir + "NumberFormatinTable.pdf");

NumberFormatinTable.pdf (2.5 KB)


Below page setup properties are available in Aspose Cells API. Could you please help me to apply same kind of properties in the PDF file by using Aspose PDF API?

worksheet.PageSetup.FitToPagesWide = 1;
worksheet.PageSetup.FitToPagesTall = 0;
worksheet.Zoom = 80;
if (isLetter)
  worksheet.PageSetup.PaperSize = PaperSizeType.PaperLetter;
  worksheet.PageSetup.PaperSize = PaperSizeType.PaperLegal;
worksheet.PageSetup.FooterMargin = 0.3;
worksheet.PageSetup.HeaderMargin = 0.3;
worksheet.PageSetup.LeftMarginInch = 0;
worksheet.PageSetup.RightMarginInch = 0.050;
worksheet.PageSetup.TopMarginInch = 0.2;
worksheet.PageSetup.BottomMargin = 0.2;
worksheet.PageSetup.HeaderMarginInch = 0.0;
worksheet.PageSetup.FooterMarginInch = 0.0;
worksheet.PageSetup.CenterHorizontally = true;
worksheet.PageSetup.CenterVertically = false;
worksheet.PageSetup.Orientation = PageOrientationType.Landscape;


You can set similar properties for PDF documents using Aspose.PDF such as:

Furthermore, page margins can be set using Page.PageInfo.Margin Property.