You can read all details at: Convert Chart to PDF and Images like JPG, PNG, WMF in Java
Created
January 19, 2021 22:18
-
-
Save aspose-com-gists/b459996cf88b6985fd4c775124f66467 to your computer and use it in GitHub Desktop.
Convert, Export or Render Chart to PDF or Image and pictures like JPG, PNG, BMP, TIFF, SVG, WMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input XLSX file | |
Workbook workbook = new Workbook(dataDir + "SampleExcel.xlsx"); | |
for (int sheet = 0 ; sheet < workbook.getWorksheets().getCount() ; sheet++) | |
{ | |
// Access required worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(sheet); | |
for (int i =0 ; i<worksheet.getCharts().getCount() ; i++) | |
{ | |
// Access specific chart | |
com.aspose.cells.Chart chart = worksheet.getCharts().get(i); | |
// Create an instance of ImageOrPrintOptions and set a few properties | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
options.setVerticalResolution(300); | |
options.setHorizontalResolution(300); | |
options.setQuality(100); | |
// Set image type for output format | |
options.setImageType(com.aspose.cells.ImageType.PNG); | |
// Render the chart to image | |
chart.toImage(dataDir + "chart_" + (i+1) + "_" + worksheet.getName() + ".png", options); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input XLSX file | |
Workbook workbook = new Workbook(dataDir + "SampleExcel.xlsx"); | |
// Access required worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access specific chart | |
Chart chart = worksheet.getCharts().get(1); | |
// Create an instance of ImageOrPrintOptions and set a few properties | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
options.setVerticalResolution(300); | |
options.setHorizontalResolution(300); | |
options.setQuality(100); | |
// Set image type for output format | |
options.setImageType(ImageType.PNG); | |
// Render the chart to image | |
chart.toImage(dataDir + "chart.png", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input XLSX file | |
Workbook workbook = new Workbook(dataDir + "SampleExcel.xlsx"); | |
// Access required worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Make sure there is atleast one chart in the workbook | |
if(worksheet.getCharts().getCount() > 0) | |
{ | |
// Access specific chart | |
com.aspose.cells.Chart chart = worksheet.getCharts().get(1); | |
// Render the chart to PDF | |
chart.toPdf(dataDir + "FirstChart.pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment