[]
DsExcel allows you to arrange pages from multiple worksheets on a single page in a PDF document. This is useful when related data is stored in different worksheets and needs to be presented together.
To export the worksheet pages, create a PrintManager instance and call the paginate() method to generate the pagination information for the workbook. Then, create a page in a GcPdfDocument and use the draw() method to arrange the paginated pages in the required number of rows and columns. Finally, call the GcPdfDocument.Save() method to save the PDF document.
The pagination result is based on the print area and page setup of each worksheet. Therefore, a worksheet may generate one or more pages. In the following example, the paginated pages are arranged in one row and two columns on a single PDF page.
Note: In order to export multiple sheets to one page, you should have a valid license for Document Solutions for PDF.
Refer to the following example code to allow users to export multiple worksheets to a single page in the PDF file.
// 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();
}