Java: Add a Text Box to a Chart in Excel

2021-11-10 08:49:20 Written by Koohji

Text box allows people to enter text in it and move it arbitrarily. When dealing with the chart in Excel document, if the text description of the original chart is not specific enough, you can add additional information to the chart by adding text boxes to it. This article will introduce how to add a text box to a chart programmatically using Spire.XLS for Java.

Install Spire.XLS for Java

First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>16.3.2</version>
    </dependency>
</dependencies>

Add a Text Box to a Chart

The detailed steps are listed as below.

  • Create a Workbook instance and load a sample Excel document using Workbook.loadFromFile() method.
  • Get a specified worksheet using Workbook.getWorksheets().get() method.
  • Get a specific chart using Worksheet.getCharts().get() method.
  • Add a text box to the chart using Chart.getShapes().addTextBox() method, and then add text content in the text box using ITextBoxLinkShape.setText() method.
  • Set the size and position of the added text box using the method offered by ITextBoxLinkShape interface.
  • Save the document to file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.*;
import com.spire.xls.core.*;

public class addTextBoxToChart {
    public static void main(String[] args)throws Exception {
        //Create a Workbook instance
        Workbook workbook = new Workbook();

        //Load an Excel document
        workbook.loadFromFile("DoughnutChart.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Get the first chart
        Chart chart = sheet.getCharts().get(0);

        //Add a text box to the chart
        ITextBoxLinkShape textbox = chart.getShapes().addTextBox();
        textbox.setText("Modified by Louis on September 06, 2021");

        //Set the size and position of the text box
        textbox.setWidth(1100);
        textbox.setHeight(480);
        textbox.setLeft(2800);
        textbox.setTop(480);

        //Save the result file
        workbook.saveToFile("addTextBoxToChart.xlsx", ExcelVersion.Version2013);
    }
}

Java: Add a Text Box to a Chart in Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Spire.PDF for Java offers PdfDocument.saveAsImage() method to convert PDF document to image. From Version 4.11.1, Spire.PDF for Java supports to set the transparent value for the background of the resulted images during PDF to image conversion. This article will show you how to convert PDF to images with transparent background in Java applications.

Install Spire.PDF for Java

First of all, you need to add the Spire.PDF.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>12.4.4</version>
    </dependency>
</dependencies>

Convert PDF to Images with Transparent Background

  • Create an object of PdfDocument class.
  • Load a sample PDF document using PdfDocument.loadFromFile() method.
  • Specify the transparent value for the background of the resulted images using PdfDocument.getConvertOptions().setPdfToImageOptions() method.
  • Save the document to images using PdfDocument.saveAsImage() method.
  • Java
import com.spire.pdf.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;


public class PdftoImage {
    public static void main(String[] args) throws Exception {

        //Create an object of PdfDocument class.
        PdfDocument pdf = new PdfDocument();
        
        //Load the sample PDF document
        pdf.loadFromFile("Sample.pdf");
        
        //Specify the background transparent value as 0 during PDF to image conversion.
        pdf.getConvertOptions().setPdfToImageOptions(0);

        //Save PDF to .png image
        BufferedImage image = pdf.saveAsImage(0);
        File file = new File( String.format("ToImage.png"));
        ImageIO.write(image, "PNG", file);
    }
}

Java: Convert PDF to Images with Transparent Background

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

PowerPoint documents signed with digital signatures can help recipients check if they have been altered since they were signed. If any changes are made, the signatures will become invalid immediately. Therefore, before you edit a PowerPoint document, you should check if it has been digitally signed or not. In this article, you will learn how to achieve this task programmatically in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>11.3.5</version>
    </dependency>
</dependencies>

Verify if a PowerPoint Document is Digitally Signed

Spire.Presentation for Java provides the Presentation.isDigitallySigned() method to detect if a PowerPoint document is digitally signed or not. If the method returns true, then it means the document is digitally signed.

The following are the detailed steps to implement this function:

  • Create a Presentation instance.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Detect if the document is digitally signed or not using Presentation.isDigitallySigned() method.
  • Java
import com.spire.presentation.Presentation;

public class VerifyIfPPTisDigitallySigned {
    public static void main(String []args) throws Exception {
        //Create a Presentation instance
        Presentation ppt = new Presentation();
        //Load a PowerPoint document
        ppt.loadFromFile("Sample.pptx");

        //Verify if the document is digitally signed or not
        if (ppt.isDigitallySigned()) {
            System.out.println("This document is digitally signed");
        } else {
            System.out.println("This document is not digitally signed");
        }
    }
}

Java: Verify if a PowerPoint Document is Digitally Signed

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

page 22