DsExcel .NET enables users to export different headers on different pages of the PDF file. This feature is useful especially when you have different information on each page of the PDF file and you want to provide different headers to each page of the PDF.
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.
C# |
Copy Code |
---|---|
// 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); |