- Document Solutions for Excel, Java Edition Overview
- Key Features
- Getting Started
- Features
- Templates
-
File Operations
- Import and Export .xlsx Document
-
Export to PDF
- Configure Fonts and Set Style
- Customize Border Style
- Export Pivot Table Styles And Format
- Export Shapes
- Export Borders
- Export Conditional Formatting
- Control Pagination
- Export Fills
- Export Picture
- Export Charts
- Export Sparkline
- Export Table
- Export Text
- Export Vertical Text
- Shrink To Fit With Text Wrap
- Export Slicers
- Export Barcodes
- Export Signature Lines
- Export Form Controls to Form Fields
- Support Security Options
- Support Document Properties
- Adjust Column Width and Row Height
- Support Sheet Background Image
- Support Background Color Transparency
- Track Export Progress
- Export to HTML
- Working With Page Setup
- Import and Export CSV File
- Import CSV File with Custom Parser
- Import and Export CSV Files with Delimiters
- Import and Export SpreadJS Files
- Import and Export Macros
- Import and Export Excel Templates
- Import and Export OLE Objects
- Convert to Image
- Import and Export Excel Options
- Use JDK 8 Date Time API
- Document Solutions Data Viewer
- API Reference
- Release Notes
(Showing Draft Content)
Track Export Progress
DsExcel provides getPagePrinting and getPagePrinted events in PdfSaveOptions class to track the export progress of a workbook to PDF. The getPagePrinting event occurs before printing a page and provides setSkipThisPage method to skip pages while exporting. Similarly, the getPagePrinted event occurs after printing a page and provides setHasMorePages method to exit PDF exporting.
Display Export Progress
Refer to the following example code to display the export progress of a workbook to PDF.
// Create to a pdf file stream
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("PagePrintEventsTrackProgress.pdf");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create a new workbook
Workbook workbook = new Workbook();
IWorksheet activeSheet = workbook.getActiveSheet();
activeSheet.getRange("A1").setValue(1);
activeSheet.getRange("A2:A100").setFormulaR1C1("=R[-1]C+1");
PdfSaveOptions options = new PdfSaveOptions();
options.getPagePrintingEvent().addListener(
(sender, e) -> System.out.println(String.format("Printing page %1$s of %2$s", e.getPageNumber(), e.getPageCount())));
activeSheet.getPageSetup().setCenterHeader("Page &P of &N");
workbook.save(outputStream, options);
// Close the file stream
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Skip a Page while Exporting
Refer to the following example code to skip second page while exporting a workbook to PDF.
// Create to a pdf file stream
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("PagePrintEventsSkipPage.pdf");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create a new workbook
Workbook workbook = new Workbook();
IWorksheet activeSheet = workbook.getActiveSheet();
activeSheet.getRange("A1").setValue(1);
activeSheet.getRange("A2:A100").setFormulaR1C1("=R[-1]C+1");
PdfSaveOptions options = new PdfSaveOptions();
options.getPagePrintingEvent().addListener((sender, e) -> {
if (e.getPageNumber() == 2) {
e.setSkipThisPage(true);
}
});
activeSheet.getPageSetup().setCenterHeader("Page &P of &N");
workbook.save(outputStream, options);
// Close the file stream
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Exit Exporting
Refer to the following example code to exit PDF exporting after second page.
// Create to a pdf file stream
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("PagePrintEventsExitPrinting.pdf");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create a new workbook
Workbook workbook = new Workbook();
IWorksheet activeSheet = workbook.getActiveSheet();
activeSheet.getRange("A1").setValue(1);
activeSheet.getRange("A2:A100").setFormulaR1C1("=R[-1]C+1");
PdfSaveOptions options = new PdfSaveOptions();
options.getPagePrintedEvent().addListener((sender, e) -> {
if (e.getPageNumber() == 2) {
e.setHasMorePages(false);
}
});
activeSheet.getPageSetup().setCenterHeader("Page &P of &N");
workbook.save(outputStream, options);
// Close the file stream
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}