Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active November 21, 2021 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/98212012f8ebdca9891092e613998f76 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/98212012f8ebdca9891092e613998f76 to your computer and use it in GitHub Desktop.
Convert Excel Spreadsheet to PDF in Java
/*
* Convert the specified Cell Range of specified Excel sheets to PDF format in Java
*/
// Prepare Load options and Range for the source XLSX file
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setConvertRange("A1:C20");
Converter converter = new Converter("path/spreadsheet.xlsx", loadOptions);
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPageNumber(1);
convertOptions.setPagesCount(1);
converter.convert("path/convert-cell-range.pdf", convertOptions);
/*
* Convert all the Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
converter.convert("path/all-sheets-converted.pdf", new PdfConvertOptions());
/*
* Convert sequence of Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPageNumber(1);
convertOptions.setPagesCount(2);
converter.convert("path/sequential-conversion.pdf", convertOptions);
/*
* Convert the specified list of Excel sheets to PDF format in Java
*/
Converter converter = new Converter("path/spreadsheet.xlsx");
PdfConvertOptions convertOptions = new PdfConvertOptions();
convertOptions.setPages(Arrays.asList(1,3));
converter.convert("path/specific-sheets-conversion.pdf", convertOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment