[]
        
(Showing Draft Content)

Customize Page Content, Headers, and Footers

DsExcel allows users to customize the content and print settings of individual pages in an exported PDF file. You can define page ranges, title rows, title columns, row and column headers, page numbers, page counts, paper dimensions, margins, headers, and footers according to the requirements of the document.

Export Different Headers On Different Pages

In order to configure different headers for different pages in the PDF file, you can use the TitleRowStart property, the TitleRowEnd property, and other properties of the RepeatSetting class. When you are done, simply create an instance of the PrintManager class, get the default pagination information using the Paginate() method and finally save your PDF file using the SavePDF() method.

Refer to the following example code in order to export different headers on different pages while exporting to a PDF file.

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

IList<RepeatSetting> repeatSettings = new List<RepeatSetting>();

// The title rows of the "B2:F87" is "$2:$2"
RepeatSetting repeatSetting = new RepeatSetting();
repeatSetting.TitleRowStart = 1;
repeatSetting.TitleRowEnd = 1;
repeatSetting.Range = worksheet.Range["B2:F87"];
repeatSettings.Add(repeatSetting);

// The title rows of the "B89:F146" is "$89:$89"
RepeatSetting repeatSetting2 = new RepeatSetting();
repeatSetting2.TitleRowStart = 88;
repeatSetting2.TitleRowEnd = 88;
repeatSetting2.Range = worksheet.Range["B89:F146"];
repeatSettings.Add(repeatSetting2);

// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();
worksheet.PageSetup.RightMargin = 10;

// Get the pagination information of the worksheet
IList<PageInfo> pages = printManager.Paginate(worksheet, null, repeatSettings);

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

Export Last Page Without Headers

DsExcel enables users to export the last page of a PDF file without headers while keeping the headers intact in rest of the pages across the PDF file. For instance - While saving a workbook to a PDF file, you may sometimes have data in the last page of the PDF that doesn't need any headers. In such a scenario, this feature can be helpful in order to save the last page of the PDF without displaying any header information.

In order to export the last page without headers while saving to a PDF file, you need to first get the default pagination by using the Paginate() method of the PrintManager class. Then, you can use the PageContent property of the PageInfo class and the TitleRowStart property of the PageContentInfo class in order to modify the header index of the last page. When you are done, simply save your file using the SavePDF() method.

Refer to the following example code to allow users to save the last page of the PDF without any headers while exporting to a PDF file.

// Initialize workbook
Workbook workbook = new Workbook();

// Open Excel file
workbook.Open("ExcelData.xlsx");

// Fetch default worksheet
IWorksheet worksheet = workbook.Worksheets[0];

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

// Repeat rows at the top of each page while saving PDF
worksheet.PageSetup.PrintTitleRows = "$1:$2";

// Get the natural pagination information of the workbook
IList<PageInfo> pages = printManager.Paginate(workbook);

// Modify the print header of the last page
pages[pages.Count - 1].PageContent.TitleRowStart = -1;

// Save the modified pages into PDF file
printManager.SavePDF("98-ExportLastPageWithoutHeaders.pdf", pages);

Export Custom Page Information

DsExcel allows you to customize the page information generated when exporting a workbook to PDF. You can modify the page content, page settings, page number, page count, headers, footers, margins, and paper size before saving the PDF file.

Use the PrintManager.Paginate method to generate the default page information. You can then update the returned PageInfo objects and pass the modified page collection to the SavePDF() method.

The following API types provide access to different parts of the page information:

  • PageInfo - 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.

  • PageContentInfo - 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.

  • PageSettings - The PageSettings object contains all the properties effecting the page settings including the paper width, paper height, page margins, page header, page footer, etc.

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<PageInfo> 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);