[]
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.
In order to configure different headers for different pages in the PDF file, you can use the setTitleRowStart() method, the setTitleRowEnd() method, and other methods 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 savePageInfosToPDF() 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.getWorksheets().get(0);
List<RepeatSetting> repeatSettings = new ArrayList<RepeatSetting>();
// The title rows of the "B2:F87" is "$2:$2".
RepeatSetting repeatSetting = new RepeatSetting();
repeatSetting.setTitleRowStart(1);
repeatSetting.setTitleRowEnd(1);
repeatSetting.setRange(worksheet.getRange("B2:F87"));
repeatSettings.add(repeatSetting);
// The title rows of the "B89:F146" is "$89:$89".
RepeatSetting repeatSetting2 = new RepeatSetting();
repeatSetting2.setTitleRowStart(88);
repeatSetting2.setTitleRowEnd(88);
repeatSetting2.setRange(worksheet.getRange("B89:F146"));
repeatSettings.add(repeatSetting2);
// Create an instance of the PrintManager class.
PrintManager printManager = new PrintManager();
worksheet.getPageSetup().setRightMargin(10);
// Get the pagination information of the worksheet.
List<PageInfo> pages = printManager.paginate(worksheet, null, repeatSettings);
// Save the modified pages into pdf file.
printManager.savePageInfosToPDF("ManageHeadersOnDifferentPages.pdf", pages);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 setPageContent() method of the PageInfo class and the setTitleRowStart() method 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 savePageInfosToPDF() 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.getWorksheets().get(0);
// Create an instance of the PrintManager class.
PrintManager printManager = new PrintManager();
// Rows to be repeated on the top of each page, while saving pdf.
worksheet.getPageSetup().setPrintTitleRows("$1:$2");
// Get the default pagination information of the workbook.
List<PageInfo> pages = printManager.paginate(workbook);
// Modify the print header of the last page.
pages.get(pages.size() - 1).getPageContent().setTitleRowStart(-1);
// Save the modified pages into pdf file.
printManager.savePageInfosToPDF("ExportLastPageWithoutHeaders.pdf", pages);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 paginate() method to generate the default page information. You can then update the returned PageInfo objects and pass the modified page collection to the savePageInfosToPDF() method.
The following API types provide access to different parts of the page information:
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 methods 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.getWorksheets().get(0);
// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();
/* Get the default pagination information of the worksheet.
The first page of the natural pagination is "A1:F37",
the second page is from row "A38:F73" */
List<PageInfo> pages = printManager.paginate(worksheet);
// Get Custom Page Information and Export it to PDF
// The first page is "A1:F36"
pages.get(0).getPageContent().setRange(worksheet.getRange("A1:F36"));
// The center header of the first page will show the text "Budget summary report"
pages.get(0).getPageSettings().setCenterHeader("&KFF0000&18 Budget summary report");
// The center footer of the first page will show the page number "1"
pages.get(0).getPageSettings().setCenterFooter("&KFF0000&16 Page &P");
// The second page is "A37:F73"
pages.get(1).getPageContent().setRange(worksheet.getRange("A37:F73"));
// Save the modified pages into pdf file
printManager.savePageInfosToPDF("CustomPageInfos.pdf", pages);