This article will demonstrate how to set text transparency in PowerPoint using Free Spire.Presentation for Java.
Import jar dependency (2 Methods)
● Download the free library and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.
● You can also add the jar dependency to your maven project by adding the following configurations to the pom.xml.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
Sample Code
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class TextTransparency {
public static void main(String[] args) throws Exception {
//Create a PowerPoint document
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//Add a shape
IAutoShape textbox = presentation .getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(50, 70, 300, 120));
textbox.getShapeStyle().getLineColor().setColor(new Color(1,1,1,0));
textbox.getFill().setFillType(FillFormatType.NONE);
//Remove default paragraphs
textbox.getTextFrame().getParagraphs().clear();
//Add three paragraphs and apply colors with different alpha values to the text
int alpha = 55;
for (int i = 0; i < 3; i++)
{
textbox.getTextFrame().getParagraphs().append(new ParagraphEx());
textbox.getTextFrame().getParagraphs().get(i).getTextRanges().append(new PortionEx("Text Transparency"));
textbox.getTextFrame().getParagraphs().get(i).getTextRanges().get(0).getFill().setFillType(FillFormatType.NONE);
textbox.getTextFrame().getParagraphs().get(i).getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
textbox.getTextFrame().getParagraphs().get(i).getTextRanges().get(0).getFill().getSolidColor().setColor(new Color(176, 48, 96, alpha));
alpha += 100;
}
//Save to file
presentation.saveToFile("TextTransparency.pptx", FileFormat.PPTX_2013);
}
}
Top comments (0)