Document Solutions for Excel, Java Edition | Document Solutions
File Operations / Export to PDF / Control Pagination / Export Multiple Sheets To One Page
In This Topic
    Export Multiple Sheets To One Page
    In This Topic

    DsExcel Java enables users to export multiple worksheets to a single page in the PDF file . 

    This feature is useful especially when you want to analyse all the crucial data at one place in order to facilitate the sharing, manipulation and printing of data in an efficient way. For instance - let's say you have a workbook with multiple worksheets wherein you want to export the content of some worksheets (containing similar type of data) so that all the related data appears on the same page and is saved into a specific page in the PDF file. In this scenario, you can use this feature to export and print data from more than one worksheet to a single page in the PDF file as per your custom requirements and preferences.

    In order to export multiple worksheets into a single page of the PDF file, users need to create an instance of the PrintManager class, get the default pagination settings of the workbook using the paginate() method, use the draw() method of the PrintManager class and finally save the PDF file.   

    Using Code

    Refer to the following example code to allow users to export multiple worksheets to a single page in the PDF file.

    Java
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
            
    // Open Excel file
    workbook.open("MultipleSheetsOnePage.xlsx");
    
    // Create a PDF document
    PDDocument doc = new PDDocument();
            
    // This page will save data for multiple pages
    PDPage page = new PDPage();
    doc.addPage(page);
    
    // Create an instance of the PrintManager class
    PrintManager printManager = new PrintManager();
    
    // Get the pagination information of the workbook
    List<PageInfo> pages = printManager.paginate(workbook);
    
    /* Divide the multiple pages into 1 rows and 2 columns 
       and printed them on one page */
    printManager.draw(doc, page, pages, 1, 2);
    
    // Save the document to pdf file
    try 
    { 
      doc.save(outputStream); doc.close(); 
    }
    catch (IOException e)
    { 
      e.printStackTrace(); 
    }
    
    // Close the file stream
    try 
    { 
    outputStream.close(); 
    } 
    catch (IOException e)
    { 
     e.printStackTrace(); 
    }