[]
Use this class to configure PDF-specific export behavior, such as shrink-to-fit handling for wrapped text, document properties, security settings, form field export, background image printing, transparent cell rendering, open-action JavaScript, and whether automatically merged cells are included.
This class extends SaveOptionsBase and is typically passed to a workbook save operation that targets the PDF file format.
worksheet.getRange("A1").setValue("Quarterly Report");
PdfSaveOptions options = new PdfSaveOptions();
options.setPrintBackgroundPicture(true);
options.setIncludeAutoMergedCells(true);
options.getShrinkToFitSettings().setMinimumFont(10);
workbook.save("path/to/output.pdf", options);
booleanbooleanbooleanbooleanvoidvoidsetFormFields(boolean value) voidsetIncludeAutoMergedCells(boolean value) voidsetOpenActionScript(String openActionScript) voidsetPDFRenderEngin(IPDFRenderEngine pdfPrinter) voidsetPrintBackgroundPicture(boolean value) voidsetPrintTransparentCell(boolean value) voidtoString()getFileFormat, setFileFormatThis constructor initializes the options to use SaveFileFormat.Pdf and creates the shrink-to-fit settings that can be accessed through getShrinkToFitSettings().
PdfSaveOptions options = new PdfSaveOptions();
options.setFormFields(true);
options.setPrintBackgroundPicture(true);
workbook.save("path/to/output.pdf", options);
Use this option to set a custom PDF render engine for PDF export. Usually, you do not need to set it.
Workbook workbook = new Workbook();
workbook.getActiveSheet().getRange("A1").setValue("Quarterly Report");
CustomPdfRenderEngine renderEngine = new CustomPdfRenderEngine();
renderEngine.addFontMapping("Calibri", "Arial");
PdfSaveOptions options = new PdfSaveOptions();
options.setPDFRenderEngin(renderEngine);
IPDFRenderEngine currentEngine = options.getPDFRenderEngin();
workbook.save(new ByteArrayOutputStream(), options);
null if no custom engine is set.Use this option to set a custom PDF render engine for PDF export. Usually, you do not need to set it.
Workbook workbook = new Workbook();
workbook.getActiveSheet().getRange("A1").setValue("Quarterly Report");
CustomPdfRenderEngine renderEngine = new CustomPdfRenderEngine();
renderEngine.addFontMapping("Calibri", "Arial");
PdfSaveOptions options = new PdfSaveOptions();
options.setPDFRenderEngin(renderEngine);
workbook.save(new ByteArrayOutputStream(), options);
pdfPrinter - The PDF render engine to use, or null to clear the custom engine.When this option is enabled, the sheet background image is rendered in the center of the exported PDF page.
PdfSaveOptions options = new PdfSaveOptions();
options.setPrintBackgroundPicture(true);
boolean printBackgroundPicture = options.getPrintBackgroundPicture();
workbook.save("path/to/output.pdf", options);
true if the worksheet background image is printed on the page during PDF export; otherwise, false.When this option is enabled, the sheet background image is rendered in the center of the exported PDF page.
PdfSaveOptions options = new PdfSaveOptions();
options.setPrintBackgroundPicture(true);
workbook.save("path/to/output.pdf", options);
value - true if the worksheet background image is printed on the page during PDF export; otherwise, false.The default value is false. When this property is true, transparent cell background colors are preserved during PDF export so content such as background images can remain visible through the cell fill.
PdfSaveOptions options = new PdfSaveOptions();
options.setPrintTransparentCell(true);
boolean printTransparentCell = options.getPrintTransparentCell();
workbook.save("path/to/output.pdf", options);
true if the transparency of the cell's background color is printed on the page; otherwise, false.The default value is false. When this property is true, transparent cell background colors are preserved during PDF export so content such as background images can remain visible through the cell fill.
PdfSaveOptions options = new PdfSaveOptions();
options.setPrintTransparentCell(true);
workbook.save("path/to/output.pdf", options);
value - true if the transparency of the cell's background color is printed on the page; otherwise, false.The returned IShrinkToFitSettings object lets you control how wrapped text is reduced to fit within its cell when a workbook is saved as PDF, including whether wrapped text can shrink, the minimum font size, and the ellipsis string.
PdfSaveOptions options = new PdfSaveOptions();
IShrinkToFitSettings settings = options.getShrinkToFitSettings();
settings.setCanShrinkToFitWrappedText(true);
settings.setMinimumFont(10);
workbook.save("path/to/output.pdf", options);
Use setDocumentProperties(DocumentProperties) to assign PDF metadata such as title, author, subject, keywords, creator, producer, creation date, modify date, and PDF version before retrieving it.
PdfSaveOptions options = new PdfSaveOptions();
DocumentProperties documentProperties = new DocumentProperties();
documentProperties.setTitle("Quarterly Sales Summary");
options.setDocumentProperties(documentProperties);
DocumentProperties properties = options.getDocumentProperties();
workbook.save("path/to/output.pdf", options);
Use this method to assign a DocumentProperties instance that defines PDF metadata such as the title, author, subject, keywords, creator, producer, creation date, modification date, and PDF version.
PdfSaveOptions options = new PdfSaveOptions();
DocumentProperties documentProperties = new DocumentProperties();
documentProperties.setTitle("Quarterly Sales Summary");
options.setDocumentProperties(documentProperties);
workbook.save("path/to/output.pdf", options);
value - The DocumentProperties instance that defines the PDF document properties.Use this method to retrieve the open action script configured by setOpenActionScript(String) for PDF export.
Security: PDF open action JavaScript runs when the exported PDF is opened. Use only fixed, trusted, and reviewed scripts. Do not pass external or user-controlled input to this property. Leave it unset unless the PDF explicitly requires an open action.
PdfSaveOptions options = new PdfSaveOptions();
String trustedOpenActionScript = "this.dirty = false;";
options.setOpenActionScript(trustedOpenActionScript);
String openActionScript = options.getOpenActionScript();
workbook.save("path/to/output.pdf", options);
Security: PDF open action JavaScript runs when the exported PDF is opened. Use only fixed, trusted, and reviewed scripts. Do not pass external or user-controlled input to this property. Leave it unset unless the PDF explicitly requires an open action.
PdfSaveOptions options = new PdfSaveOptions();
String trustedOpenActionScript = "this.dirty = false;";
options.setOpenActionScript(trustedOpenActionScript);
workbook.save("path/to/output.pdf", options);
openActionScript - The JavaScript to be executed when the saved PDF file is opened.Returns the PdfSecurityOptions object that defines PDF passwords and permissions for this save operation. Use setSecurityOptions(PdfSecurityOptions) to assign the security settings.
PdfSaveOptions options = new PdfSaveOptions();
PdfSecurityOptions securityOptions = new PdfSecurityOptions();
String userPassword = getPdfUserPassword();
securityOptions.setUserPassword(userPassword);
options.setSecurityOptions(securityOptions);
PdfSecurityOptions pdfSecurityOptions = options.getSecurityOptions();
workbook.save("path/to/output.pdf", options);
Assign a PdfSecurityOptions object to define PDF passwords and permissions for this save operation, such as printing, modifying, or extracting content.
PdfSaveOptions options = new PdfSaveOptions();
PdfSecurityOptions securityOptions = new PdfSecurityOptions();
String userPassword = getPdfUserPassword();
securityOptions.setUserPassword(userPassword);
securityOptions.setPrintPermission(false);
options.setSecurityOptions(securityOptions);
workbook.save("path/to/output.pdf", options);
value - The PdfSecurityOptions object that defines the PDF security settings. null removes the current security settings.This option controls whether auto-merge information is applied during PDF export. The default value is false.
PdfSaveOptions options = new PdfSaveOptions();
options.setIncludeAutoMergedCells(true);
boolean includeAutoMergedCells = options.getIncludeAutoMergedCells();
workbook.save("path/to/output.pdf", options);
true if automatically merged cells are included during PDF export; otherwise, false.This option controls whether auto-merge information is applied during PDF export. The default value is false.
PdfSaveOptions options = new PdfSaveOptions();
options.setIncludeAutoMergedCells(true);
workbook.save("path/to/output.pdf", options);
value - true if automatically merged cells are included during PDF export; otherwise, false.
final boolean[] pagePrintingInvoked = new boolean[] { false };
PdfSaveOptions options = new PdfSaveOptions();
options.getPagePrintingEvent().addListener(new EventHandler<PagePrintingEventArgs>() {
public void invoke(Object sender, PagePrintingEventArgs e) {
pagePrintingInvoked[0] = true;
}
});
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workbook.save(outputStream, options);
worksheet.getRange("A1:A96").setValue(1);
final boolean[] hasMorePages = new boolean[] { false };
PdfSaveOptions options = new PdfSaveOptions();
options.getPagePrintedEvent().addListener(new EventHandler<PagePrintedEventArgs>() {
public void invoke(Object sender, PagePrintedEventArgs e) {
hasMorePages[0] |= e.getHasMorePages();
}
});
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workbook.save(outputStream, options);
When this property is true, supported Excel form controls are exported as PDF form fields. Not all controls and properties are supported.
PdfSaveOptions options = new PdfSaveOptions();
options.setFormFields(true);
boolean formFields = options.getFormFields();
workbook.save("path/to/output.pdf", options);
true if Excel form controls will be exported as PDF form fields; otherwise, false. The default value is false.When this property is true, supported Excel form controls are exported as PDF form fields. Not all controls and properties are supported.
PdfSaveOptions options = new PdfSaveOptions();
options.setFormFields(true);
workbook.save("path/to/output.pdf", options);
value - true if Excel form controls will be exported as PDF form fields; otherwise, false. The default value is false.The returned map stores custom PDF border settings for each BorderLineStyle. Add or update entries in this map to override the exported border width and dash pattern for specific border line styles.
PdfSaveOptions options = new PdfSaveOptions();
CustomBorderStyle thinBorderStyle = new CustomBorderStyle();
thinBorderStyle.setBorderWidth(0.4);
options.getBorderOptions().put(BorderLineStyle.Thin, thinBorderStyle);
workbook.save("path/to/output.pdf", options);
BorderLineStyle.