The background of a PowerPoint presentation sets the tone and mood of the presentation and can greatly enhance the aesthetic and impact of the slides. There are five types of backgrounds available in PowerPoint presentations, solid color backgrounds, gradient backgrounds, picture backgrounds, texture backgrounds, and patterned backgrounds. They each apply to different usage scenarios. For example, a professional business presentation may benefit from a clean and simple solid color background, while a creative presentation may use inspiring and interesting picture backgrounds to capture the audience's attention. This article is going to show how to set backgrounds for PowerPoint presentations through Java programs 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.5.1</version>
    </dependency>
</dependencies>

Set a Solid Color Background for a PowerPoint Presentation

Before customizing the background, it is necessary to use the SlideBackground.setType(BackgroundType.CUSTOM) method to allow the customization of the background. Then, the background type can be set to solid color background using the SlideBackground.getFill().setFillType(FillFormatType.SOLID) method, and the color can be set using the FillFormat.getSolidColor().setColor() method.

The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Get the first slide using Presentation.getSlides().get() method.
  • Get the background of the slide using ISlide.getSlideBackground() method.
  • Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
  • Set the fill type of the background to solid color using SlideBackground.getFill().setFillType(FillFormatType.SOLID) method.
  • Customize the background color using FillFormat.getSolidColor().setColor() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormat;
import com.spire.presentation.drawing.FillFormatType;
import org.w3c.dom.css.RGBColor;

import java.awt.*;

public class SolidColor {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation ppt = new Presentation();

        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the background
        SlideBackground background = slide.getSlideBackground();

        //Set the background type to custom
        background.setType(BackgroundType.CUSTOM);

        //Set the background fill type to solid color
        background.getFill().setFillType(FillFormatType.SOLID);

        //Set the background color
        FillFormat fillFormat = background.getFill();
        fillFormat.getSolidColor().setColor(new Color(199, 213, 237));

        //Save the presentation
        ppt.saveToFile("SolidColorBackground.pptx", FileFormat.AUTO);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

Set a Gradient Background for a PowerPoint Presentation

Gradient background can be set by setting the background type to Gradient Background and then setting the gradient type, color, and angle. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Get the first slide using Presentation.getSlides().get() method.
  • Get the background of the slide using ISlide.getSlideBackground() method.
  • Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
  • Set the fill type of the background to gradient using SlideBackground.getFill().setFillType(FillFormatType.GRADIENT) method.
  • Set the gradient type to linear gradient using GradientFillFormat.setGradientShape(GradientShapeType.LINEAR) method.
  • Add the gradient stops and set the gradient colors using GradientFillFormat.getGradientStops().append() method.
  • Set the angle of the linear gradient using GradientFillFormat.getLinearGradientFill().setAngle() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;

import java.awt.*;

public class Gradient {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation ppt = new Presentation();

        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the background
        SlideBackground background = slide.getSlideBackground();

        //Set the background type to custom
        background.setType(BackgroundType.CUSTOM);

        //Set the background fill type to gradient color
        background.getFill().setFillType(FillFormatType.GRADIENT);

        //Set the gradient type to linear
        GradientFillFormat gradient = background.getFill().getGradient();
        gradient.setGradientShape(GradientShapeType.LINEAR);

        //Add gradient stops and set the colors
        gradient.getGradientStops().append(0f, new Color(230, 255, 255));
        gradient.getGradientStops().append(0.5f, new Color(255, 255, 255));
        gradient.getGradientStops().append(1f, new Color(199, 213, 237));

        //Set the angle of the linear gradient
        gradient.getLinearGradientFill().setAngle(90);

        //Save the presentation
        ppt.saveToFile("GradientBackground.pptx", FileFormat.AUTO);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

Set a Picture Background for a PowerPoint Presentation

To set the picture background, set the background type to picture, set the picture fill type to stretch fill, and then set the background image. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Load a picture using Presentation.getImages().append() method.
  • Get the first slide using Presentation.getSlides().get() method.
  • Get the background of the slide using ISlide.getSlideBackground() method.
  • Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
  • Set the fill type of the background to picture using SlideBackground.getFill().setFillType(FillFormatType.PICTURE) method.
  • Set the picture fill type to stretch fill using PictureFillFormat.setFillType(PictureFillType.STRETCH) method.
  • Set the transparency of the background using PictureFillFormat.getPicture().setTransparency() method.
  • Set the background image using PictureFillFormat.getPicture().setEmbedImage() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideBackground;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;

public class Picture {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation ppt = new Presentation();

        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Load a picture
        IImageData image = ppt.getImages().append(ImageIO.read(new File("background.jpg")));

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the background
        SlideBackground background = slide.getSlideBackground();

        //Set the background type to custom
        background.setType(BackgroundType.CUSTOM);

        //Set the background fill type to picture
        background.getFill().setFillType(FillFormatType.PICTURE);

        //Set the picture fill type to stretch
        PictureFillFormat pictureFillFormat = background.getFill().getPictureFill();
        pictureFillFormat.setFillType(PictureFillType.STRETCH);

        //Set the transparency of the background
        pictureFillFormat.getPicture().setTransparency(50);

        //Set the background picture
        pictureFillFormat.getPicture().setEmbedImage(image);

        //Save the presentation
        ppt.saveToFile("PictureBackground.pptx", FileFormat.AUTO);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

Set a Texture Background for a PowerPoint Presentation

Setting a texture background is similar to setting a picture background. The difference is that the image fill type needs to be changed to a tiled fill and the texture alignment needs to be set. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Load the texture using Presentation.getImages().append() method.
  • Get the first slide using Presentation.getSlides().get() method.
  • Get the background of the slide using ISlide.getSlideBackground() method.
  • Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
  • Set the fill type of the background to picture using SlideBackground.getFill().setFillType(FillFormatType.PICTURE) method.
  • Set the picture fill type to tile fill using PictureFillFormat.setFillType(PictureFillType.TILE) method.
  • Set the transparency of the background using PictureFillFormat.getPicture().setTransparency() method.
  • Set the background texture using PictureFillFormat.getPicture().setEmbedImage() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.io.File;

public class Texture {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation ppt = new Presentation();

        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Load the texture
        IImageData image = ppt.getImages().append(ImageIO.read(new File("texture.png")));

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the background
        SlideBackground background = slide.getSlideBackground();

        //Set the background type to custom
        background.setType(BackgroundType.CUSTOM);

        //Set the background fill type to picture
        background.getFill().setFillType(FillFormatType.PICTURE);

        //Set the picture fill type to tile
        PictureFillFormat pictureFillFormat = background.getFill().getPictureFill();
        pictureFillFormat.setFillType(PictureFillType.TILE);

        //Set the texture alignment
        pictureFillFormat.setAlignment(RectangleAlignment.TOP_LEFT);

        //Set the transparency of the background
        pictureFillFormat.getPicture().setTransparency(50);

        //Set the background texture
        pictureFillFormat.getPicture().setEmbedImage(image);

        //Save the presentation
        ppt.saveToFile("TextureBackground.pptx", FileFormat.AUTO);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

Set a Pattern Background for a PowerPoint Presentation

In adding a pattern background, it is necessary to set the type of pattern as well as the foreground and background colors of the pattern. The detailed steps are as follows:

  • Create an object of Presentation class.
  • Load a PowerPoint presentation using Presentation.loadFromFile() method.
  • Get the first slide using Presentation.getSlides().get() method.
  • Get the background of the slide using ISlide.getSlideBackground() method.
  • Set the background type to custom background to enable the customization of the background using SlideBackground.setType(BackgroundType.CUSTOM) method.
  • Set the fill type of the background to pattern using SlideBackground.getFill().setFillType(FillFormatType.PATTERN) method.
  • Set the pattern type using PatternFillFormat.setPatternType() method.
  • Set the foreground color of the pattern using PatternFillFormat.getForegroundColor().setColor() method.
  • Set the background color of the pattern using PatternFillFormat.getBackgroundColor().setColor() method.
  • Save the presentation using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;

public class Pattern {
    public static void main(String[] args) throws Exception {
        //Create an object of Presentation class
        Presentation ppt = new Presentation();

        //Load a PowerPoint presentation
        ppt.loadFromFile("Sample.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the background
        SlideBackground background = slide.getSlideBackground();

        //Set the background type to custom
        background.setType(BackgroundType.CUSTOM);

        //Set the background fill type to pattern
        background.getFill().setFillType(FillFormatType.PATTERN);

        //Set the pattern type
        PatternFillFormat patternFillFormat = background.getFill().getPattern();
        patternFillFormat.setPatternType(PatternFillType.DOTTED_GRID);

        //Set the foreground color of the pattern
        patternFillFormat.getForegroundColor().setColor(new Color(230, 255, 255));

        //Set the background color of the pattern
        patternFillFormat.getBackgroundColor().setColor(new Color(199, 213, 237));

        //Save the presentation
        ppt.saveToFile("PatternBackground.pptx", FileFormat.AUTO);
    }
}

Java: Set Backgrounds for PowerPoint Presentations

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.

A footer is text or other content located at the bottom of a page, usually including page numbers, dates, authors, and other information. Footers contribute to the overall professional appearance of the document by maintaining a consistent layout across all pages. By incorporating footers, PDF documents become more professional, user-friendly, and compliant with legal requirements. This article demonstrates how to add a footer to an existing PDF document in Java using Spire.PDF for Java.

Install Spire.PDF for Java

First of all, you're required 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 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.pdf</artifactId>
        <version>12.6.1</version>
    </dependency>
</dependencies>

Background Knowledge

When using Spire.PDF for Java to process an existing PDF document, the origin of the coordinate system is located at the top left corner of the page, with the x-axis extending to the right and the y-axis extending downward. Adding a footer to a page means adding content, such as text, images, automatic fields and shapes, to a specified location in the bottom blank area of the page.

Java: Add a Footer to an Existing PDF Document

If the blank area is not large enough to accommodate the content you want to add, you can consider increasing the PDF page margins.

Add a Footer to an Existing PDF Document in Java

Spire.PDF for Java offers the PdfCanvas.drawString() method, PdfCanvas.drawImage() method, PdfCanvas.drawLine() method and its similar methods, allowing users to draw text, images and shapes on a PDF page at the specified location. To add dynamic data to the footer, such as page numbers, sections, dates, you need to use the automatic fields. Spire.PDF for Java provides the PdfPageNumberField class, PdfPageCountField calss, PdfSectionNumberField class etc. to achieve the addition of dynamic information.

The following are the steps to add a footer consisting of an image and page number to a PDF document using Spire.PDF for Java.

  • Create a PdfDocument object.
  • Load a PDF document using PdfDocument.loadFromFile() method.
  • Load an image using PdfImage.fromFile() method.
  • Draw the image on the bottom blank area of a page using PdfPageBase.getCanvas().drawImage() method.
  • Create a PdfPageNumberField object, a PdfPageCountField object, and combine them in a PdfCompositefield object to return the string "Page X of Y".
  • Draw page number on the bottom blank area of a page using PdfCompositeField.draw() method.
  • Save the document to another PDF file using PdfDocument.saveToFile() method.
  • Java
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.automaticfields.PdfCompositeField;
import com.spire.pdf.automaticfields.PdfPageCountField;
import com.spire.pdf.automaticfields.PdfPageNumberField;
import com.spire.pdf.graphics.PdfBrush;
import com.spire.pdf.graphics.PdfBrushes;
import com.spire.pdf.graphics.PdfImage;
import com.spire.pdf.graphics.PdfTrueTypeFont;

import java.awt.*;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;

public class AddFooterToPdf {

    public static void main(String[] args) {

        //Create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //Load a PDF file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

        //Load an image
        PdfImage footerImage = PdfImage.fromFile("C:\\Users\\Administrator\\Desktop\\bg.jpg");

        //Create a true type font
        PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Times New Roman", Font.BOLD, 12),true);

        //Create a brush
        PdfBrush brush = PdfBrushes.getWhite();

        //Create a page number field
        PdfPageNumberField pageNumberField = new PdfPageNumberField();

        //Create a page count field
        PdfPageCountField pageCountField = new PdfPageCountField();

        //Create a composite field to combine page count field and page number field in a single string
        PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumberField, pageCountField);

        //Get the text size
        Dimension2D fontSize = font.measureString(compositeField.getText());

        //Get the page size
        Dimension2D pageSize = doc.getPages().get(0).getSize();

        //Set the position of the composite field
        compositeField.setLocation(new Point2D.Double((pageSize.getWidth() - fontSize.getWidth())/2,  pageSize.getHeight() - 45));

        //Loop through the pages in the document
        for (int i = 0; i < doc.getPages().getCount(); i++)
        {
            //Get a specific page
            PdfPageBase page = doc.getPages().get(i);

            //Draw the image on the bottom blank area
            page.getCanvas().drawImage(footerImage, 55, pageSize.getHeight() - 65, pageSize.getWidth() - 110, 50);

            //Draw the composite field on the bottom blank area
            compositeField.draw(page.getCanvas());
        }

        //Save to file
        doc.saveToFile("output/AddFooter.pdf");
        doc.dispose();
    }
}

Java: Add a Footer to an Existing PDF Document

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.

Named ranges in Excel are valuable tools that empower you to assign meaningful names to specific cells or ranges within your spreadsheets. Instead of relying on traditional cell references like A1:B10, named ranges allow you to reference data by their logical names, making your formulas more intelligible and easier to understand and maintain. This article will demonstrate how to create, edit or delete named ranges in Excel in Java 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.4.1</version>
    </dependency>
</dependencies>

Create a Named Range in Excel in Java

You can use the Workbook.getNameRanges().add(String name) method provided by Spire.XLS for Java to add a named range to an Excel workbook. Once the named range is added, you can define the cell or range of cells it refers to using the INamedRange.setRefersToRange(IXLSRange range) method. The detailed steps are as follows:

  • Initialize an instance of the Workbook class.
  • Load an Excel workbook using the Workbook.loadFromFile() method.
  • Add a named range to the workbook using the Workbook.getNameRanges().add(String name) method.
  • Get a specific worksheet in the workbook using the Workbook.getWorksheets().get(int index) method.
  • Set the cell range that the named range refers to using the INamedRange.setRefersToRange(IXLSRange range) method.
  • Save the result file using the Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.spire.xls.core.INamedRange;

public class CreateNamedRange {
    public static void main(String[] args) {
        //Initialize an instance of the Workbook class
        Workbook workbook = new Workbook();
        //Load an Excel workbook
        workbook.loadFromFile("Sample.xlsx");

        //Add a named range to the workbook
        INamedRange namedRange = workbook.getNameRanges().add("Amount");

        //Get a specific worksheet in the workbook
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Set the cell range that the named range references
        namedRange.setRefersToRange(sheet.getCellRange("D2:D5"));

        //Save the result file to a specific location
        String result = "CreateNamedRange.xlsx";
        workbook.saveToFile(result, ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java: Create, Edit or Delete Named Ranges in Excel

Edit an Existing Named Range in Excel in Java

After you've created a named range, you may want to modify its name or adjust the cells it refers to. The following are the detailed steps:

  • Initialize an instance of the Workbook class.
  • Load an Excel workbook using the Workbook.loadFromFile() method.
  • Get a specific named range in the workbook using the Workbook.getNameRanges().get(int index) method.
  • Modify the name of the named range using the INamedRange.setName(String name) method.
  • Modify the cells that the named range refers to using the INamedRange.setRefersToRange(IXLSRange range) method.
  • Save the result file using the Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.core.INamedRange;

public class ModifyNamedRange {
    public static void main(String[] args) {
        //Initialize an instance of the Workbook class
        Workbook workbook = new Workbook();
        //Load an Excel workbook
        workbook.loadFromFile("CreateNamedRange.xlsx");

        //Get a specific named range in the workbook
        INamedRange namedRange = workbook.getNameRanges().get(0);

        //Change the name of the named range
        namedRange.setName("MonitorAmount");

        //Set the cell range that the named range references
        namedRange.setRefersToRange(workbook.getWorksheets().get(0).getCellRange("D2"));

        //Save the result file to a specific location
        String result = "ModifyNamedRange.xlsx";
        workbook.saveToFile(result, ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java: Create, Edit or Delete Named Ranges in Excel

Delete a Named Range from Excel in Java

If you have made significant changes to the structure or layout of your spreadsheet, it might be necessary to delete a named range that is no longer relevant or accurate. The detailed steps are as follows:

  • Initialize an instance of the Workbook class.
  • Load an Excel workbook using the Workbook.loadFromFile() method.
  • Remove a specific named range by its index or name using the Workbook.getNameRanges().removeAt(int index) or Workbook.getNameRanges().remove(string name) method.
  • Save the result file using the Workbook.saveToFile() method.
  • Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;

public class DeleteNamedRange {
    public static void main(String[] args) {
        //Initialize an instance of the Workbook class
        Workbook workbook = new Workbook();
        //Load an Excel workbook
        workbook.loadFromFile("CreateNamedRange.xlsx");

        //Remove a specific named range by its index
        workbook.getNameRanges().removeAt(0);

        //Remove a specific named range by its name
        //workbook.getNameRanges().remove("Amount");

        //Save the result file to a specific location
        String result = "RemoveNamedRange.xlsx";
        workbook.saveToFile(result, ExcelVersion.Version2013);
        workbook.dispose();
    }
}

Java: Create, Edit or Delete Named Ranges 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.

Page 10 of 81
page 10