DsExcel Java enables users to export only some specific worksheets in the workbook (and not the entire workbook) into the pages of the PDF file.
This feature is useful especially when you have a workbook containing large number of worksheets. For instance - While saving to a PDF file, you may not want to export the entire workbook containing multiple worksheets and want only some important worksheets to be saved to the PDF file. In this scenario, you can use this feature to generate a custom PDF file as per your requirements.
In order to export specific pages to the PDF file, create an instance of the PrintManager class and get the default pagination using the paginate() method. Next, you need to specify the pages that you want to export or print. Finally, call the updatePageNumberAndPageSettings() method in order to update the indexes of the page number and the page settings for each page. When you are done, simply save your PDF file using the savePageInfosToPDF() method.
Refer to the following example code to export some specific pages to the PDF file.
Java |
Copy Code |
---|---|
// Initialize workbook Workbook workbook = new Workbook(); // Open Excel file workbook.open("PrintSpecificPDFPages.xlsx"); // Create an instance of the PrintManager class PrintManager printManager = new PrintManager(); // Get the natural pagination information of the workbook List<PageInfo> pages = printManager.paginate(workbook); // Pick some pages to print List<PageInfo> newPages = new ArrayList<PageInfo>(); newPages.add(pages.get(0)); newPages.add(pages.get(2)); /* Update the page number and the page settings of each page. The page number is continuous */ printManager.updatePageNumberAndPageSettings(newPages); // Save the pages into pdf file printManager.savePageInfosToPDF("PrintSpecificPages.pdf", newPages); |