[]
        
(Showing Draft Content)

Export Custom Page Information

GcExcel .NET enables users to save and print custom page information while exporting to a PDF file.

For instance - Sometimes, users may want to apply different page settings and display custom page number, page count, title rows, tail rows, column headers, row headers, title columns, tail columns, range, paper width, paper height, page margins, page headers, page footers etc. as per their own preferences while exporting to a PDF file or while printing a PDF file. In this scenario, they can use this feature to showcase the desired page information instead of the default page information in the PDF file.

Depending upon the specific requirements of the users, the custom page information can be exported using the following APIs:

  • Creating and using an instance of the PageInfo class - The PageInfo object represents a page containing all the information needed for printing. This includes page number, page count, page content and page settings, etc.

  • Creating and using an instance of the PageContentInfo class- The PageContentInfo object represents the data area of a page which includes row header, title rows, tail rows, column header, title columns, tail columns, range, etc.

  • Creating and using an instance of the PageSettings class- The PageSettings object contains all the properties effecting the page settings including the paper width, paper height, page margins, page header, page footer, etc.

Using Code

Refer to the following example code to allow users to export custom page information while saving the workbook to a PDF file.

// Initialize workbook
Workbook workbook = new Workbook();
        
// Open Excel file
workbook.Open("KeepTogether.xlsx");
        
// Fetch default worksheet 
IWorksheet worksheet = workbook.Worksheets[0];

// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();

/* Get the natural pagination information of the worksheet.
   The first page of the natural pagination is "A1:F37", 
   the second page is from row "A38:F73" */
IList pages = printManager.Paginate(worksheet);

// Customize the page information. The first page is "A1:F36"
pages[0].PageContent.Range = worksheet.Range["A1:F36"];
        
/* The center header of the first page will 
   show the text "Budget summary report" */
pages[0].PageSettings.CenterHeader =
"&KFF0000&18 Budget summary report";
        
/* The center footer of the first page will
   show the page number "1" */
pages[0].PageSettings.CenterFooter = 
"&KFF0000&16 Page &P";
        
// The second page is "A37:F73"
pages[1].PageContent.Range = 
worksheet.Range["A37:F73"];

// Save the modified pages into PDF file
printManager.SavePDF(@"CustomPageInfos.pdf", pages);