DsExcel Java 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:
Refer to the following example code to allow users to export custom page information while saving the workbook to a PDF file.
Java |
Copy Code |
---|---|
// 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); |