Convert Excel Chart to PDF in Java

This brief tutorial guides how to convert Excel chart to PDF in Java. It has the details to set the development environment, a list of steps to write the application, and a runnable sample code to create an Excel chart PDF in Java. You will learn different customizations of the output PDF file while converting the chart to a PDF file.

Steps to Transform Excel Chart to PDF in Java

  1. Set the environment to use Aspose.Cells for Java to create Excel chart PDF
  2. Load the sample Excel file with some charts in it
  3. Access the worksheet containing the chart(s)
  4. Get the collection of charts from the worksheet
  5. Access the target chart for rendering to a PDF file
  6. Call the toPdf() method in the Chart class to convert it to a PDF file

The above steps summarize the process of rendering an Excel graph PDF in Java. Start the process by loading the sample Excel file with graphs, followed by accessing the desired chart from the selected sheet in the loaded spreadsheet. Call the toPdf() method using the Chart class object by passing the output PDF file name, the dimensions of the output PDF file page in inches, and the alignment of the chart on the page.

Code to Convert Excel Graph to PDF in Java

This sample code changes the Excel chart to PDF in Java. The Chart class has multiple overload functions of toPdf() where you can transform the chart to a PDF file and save it into a memory stream, save the output PDF file to a stream but provide the page dimensions and alignment information, or save the chart to PDF file on the disk with the default settings. The Chart class has other features where you can refresh the pivot data before rendering the chart, set 3D chart depth percentage, and set name and placement, to list a few.

This tutorial has guided us to print a chart on PDF. If you want to create a chart in the Excel file, refer to the article on how to create Excel chart in Java.

 English