//create to a pdf file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("PrintMultiplePagesToOnePage.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } //create a new workbook Workbook workbook = new Workbook(); workbook.open(this.getResourceStream("xlsx/Multiple sheets one page.xlsx")); IWorksheet worksheet = workbook.getWorksheets().get(0); //Create a pdf document. PDDocument doc = new PDDocument(); //This page will save datas for multiple pages. PDPage page = new PDPage(); doc.addPage(page); //Create a PrintManager. PrintManager printManager = new PrintManager(); //Get the pagination information of the workbook. List 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 modified pages into 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(); }
//create to a pdf file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("PrintMultiplePagesToOnePage.pdf") } catch (e: FileNotFoundException) { e.printStackTrace() } //create a new workbook var workbook = Workbook()//close the file stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }