Other

Other (3)

This article shows you how to embed a zip file as an OLE object in a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.*;
import com.spire.presentation.drawing.IImageData;

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

public class InsertZip {

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

        //Create a Presentation object
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

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

        //Load a zip file and convert it to a byte[] object
        String filePath = "C:\\Users\\Administrator\\Desktop\\sample.zip";
        File zipFile = new File(filePath);
        FileInputStream inputStream = new FileInputStream(zipFile);
        byte[] data = new byte[(int) zipFile.length()];
        inputStream.read(data, 0, data.length);

        //Load an image file as the display icon
        File file = new File("C:\\Users\\Administrator\\Desktop\\winrar-icon.png");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = presentation.getImages().append(image);
        
        //Insert the zip file as an OLE object to the first slide
        Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight());
        IOleObject oleObject = slide.getShapes().appendOleObject("zip", data, rect);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
        oleObject.setProgId("Package");
        
        //Save to file
        presentation.saveToFile("output/InsertZip.pptx", FileFormat.PPTX_2013);
    }
}

 

Embed a Zip File in PowerPoint in Java

This article demonstrates how to insert an Excel file as an OEL object into a PowerPoint document using Spire.Presentation for Java.

import com.spire.presentation.FileFormat;
import com.spire.presentation.IOleObject;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
import com.spire.presentation.drawing.IImageData;
import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;

public class EmbedExcel {

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

        //Create a Presentation object
        Presentation ppt = new Presentation();
        ppt.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //Load an image file and add it to the image collection of the presentation
        File file = new File("C:\\Users\\Administrator\\Desktop\\image.png");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = ppt.getImages().append(image);

        //Load an Excel file and convert it to byte[] object
        String excelPath = "C:\\Users\\Administrator\\Desktop\\data.xlsx";
        File excelFile = new File(excelPath);
        FileInputStream inputStream = new FileInputStream(excelFile);
        byte[] data = new byte[(int) excelFile.length()];
        inputStream.read(data, 0, data.length);

        //Create a Rectangle2D object
        Rectangle2D rect = new Rectangle2D.Float(60, 60, image.getWidth(), image.getHeight());

        //Insert the Excel file as an OLE object to the first slide
        IOleObject oleObject = ppt.getSlides().get(0).getShapes().appendOleObject("excel", data, rect);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);
        oleObject.setProgId("Excel.Sheet.12");

        //Save to another file
        ppt.saveToFile("InsertOle.pptx", FileFormat.PPTX_2013);
    }
}

Embed an Excel File in a PowerPoint Document in Java

Adding, modifying, and removing footers in PowerPoint documents is crucial as footers can provide additional information and organizational structure to the document. By including page numbers, dates, author information, or custom text in the footer, it can help the audience better understand the presentation content and track document versions. Footers also enhance the professionalism and tidiness of the document, making it more visually appealing and readable. Modifying footers allows for updating information or adjusting formats as needed to ensure the document remains current and consistent. Removing footers can customize the document's appearance based on specific requirements or design preferences. This article will introduce how to use Spire.Presentation for Java to add, modify, and remove footers in PowerPoint documents within a Java project.

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>9.10.2</version>
    </dependency>
</dependencies>
    

Java Add Footers in PowerPoint Documents

Using Spire.Presentation, you can easily add consistent footer content to the bottom of each page in a PowerPoint document. By adding footer placeholders, page number placeholders, and time placeholders, you can ensure that the footer content on each page remains consistent. Here are the detailed steps:

  • Create a lisentation object.
  • Load a PowerPoint document using the lisentation.loadFromFile() method.
  • Set the footer visible using lisentation.setFooterVisible(true) and set the footer text.
  • Set the slide number visible using lisentation.setSlideNumberVisible(true), iterate through each slide, check for the lisence of a page number placeholder, and modify the text to the "Page X" format if found.
  • Set the date and time visible using lisentation.setDateTimeVisible(true).
  • Set the format of the date using the lisentation.setDateTime() method.
  • Save the document to a specified path using the lisentation.saveToFile() method.
  • Java
using Spire.Presentation;

namespace SpirePresentationDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Create a Presentation object
            Presentation presentation = new Presentation();

            // Load the presentation from a file
            presentation.LoadFromFile("Sample1.pptx");

            // Set the footer visible
            presentation.FooterVisible = true;

            // Set the footer text to "Spire.Presentation"
            presentation.SetFooterText("Spire.Presentation");

            // Set slide number visible
            presentation.SlideNumberVisible = true;

            // Iterate through each slide in the presentation
            foreach (ISlide slide in presentation.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    if (shape.Placeholder != null)
                    {
                        // If it is a slide number placeholder
                        if (shape.Placeholder.Type.Equals(PlaceholderType.SlideNumber))
                        {
                            TextParagraph textParagraph = (shape as IAutoShape).TextFrame.TextRange.Paragraph;
                            String text = textParagraph.Text;

                            // Modify the slide number text to "Slide X"
                            textParagraph.Text = "Slide " + text;
                        }
                    }
                }
            }

            // Set date time visible
            presentation.DateTimeVisible = true;

            // Set date time format
            presentation.SetDateTime(DateTime.Now, "MM/dd/yyyy");

            // Save the modified presentation to a file
            presentation.SaveToFile("AddFooter.pptx", FileFormat.Pptx2016);

            // Dispose of the Presentation object resources
            presentation.Dispose();
        }
    }
}

Java: Add, Modify, or Remove Footers in PowerPoint Documents

Java Modify Footers in PowerPoint Documents

To modify the footer in a PowerPoint document, you need to inspect each shape on every slide to identify footer placeholders, page number placeholders, and so on. By recognizing these placeholders, you can set specific content and formats for each type. Here are the detailed steps:

  • Create a Presentation object.
  • Load a PowerPoint document using the Presentation.loadFromFile() method.
  • Retrieve a slide using the Presentation.getSlides().get(index) method.
  • Iterate through the shapes on the slide using a for loop, inspect each shape to determine if it is a placeholder for the footer, page number, etc., and then modify its content or format accordingly.
  • Save the document to a specified path using the Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;

public class ModifyFooter {
    public static void main(String[] args) throws Exception {
        // Create a Presentation object
        Presentation presentation = new Presentation();

        // Load a presentation from a file
        presentation.loadFromFile("Sample2.pptx");

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

        // Iterate through shapes on the slide
        for (int i = 0; i < slide.getShapes().getCount(); i++) {
            // Check if the shape is a placeholder
            if (slide.getShapes().get(i).getPlaceholder() != null) {
                // Get the placeholder type
                PlaceholderType type = slide.getShapes().get(i).getPlaceholder().getType();

                // If it's a footer placeholder
                if (type == PlaceholderType.FOOTER) {
                    // Convert the shape to IAutoShape type
                    IAutoShape autoShape = (IAutoShape) slide.getShapes().get(i);

                    // Set the text content to "E-ICEBLUE"
                    autoShape.getTextFrame().setText("E-ICEBLUE");

                    // Modify the font of the text
                    ChangeFont(autoShape.getTextFrame().getParagraphs().get(0));
                }
                // If it's a slide number placeholder
                if (type == PlaceholderType.SLIDE_NUMBER) {
                    // Convert the shape to IAutoShape type
                    IAutoShape autoShape = (IAutoShape) slide.getShapes().get(i);

                    // Modify the font of the text
                    ChangeFont(autoShape.getTextFrame().getParagraphs().get(0));
                }
            }
        }

        // Save the modified presentation to a file
        presentation.saveToFile("ModifiedFooter.pptx", FileFormat.PPTX_2016);

        // Dispose of the Presentation object resources
        presentation.dispose();
    }
    static void ChangeFont(ParagraphEx paragraph)
    {
        // Iterate through each text range in the paragraph
        for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
            // Set the text style to italic
            paragraph.getTextRanges().get(i).isItalic(TriState.TRUE);

            // Set the text font
            paragraph.getTextRanges().get(i).setEastAsianFont (new TextFont("Times New Roman"));

            // Set the text font size to 34
            paragraph.getTextRanges().get(i).setFontHeight(34);

            // Set the text color
            paragraph.getTextRanges().get(i).getFill().setFillType(FillFormatType.SOLID);
            paragraph.getTextRanges().get(i).getFill().getSolidColor().setColor(Color.BLUE);
        }
    }
}

Java: Add, Modify, or Remove Footers in PowerPoint Documents

Java Remove Footers in PowerPoint Documents

To delete the footer in a PowerPoint document, you first need to retrieve content such as footer placeholders, page number placeholders, time placeholders, etc., within the slides. Once these placeholders are identified, you can locate and remove them from the collection of shapes on the slide. Here are the detailed steps:

  • Create a Presentation object.
  • Load a PowerPoint document using the Presentation.loadFromFile() method.
  • Retrieve a slide using the Presentation.getSlides().get(index) method.
  • Iterate through the shapes on the slide using a for loop, check if they are placeholders, and if they are footer placeholders, page number placeholders, time placeholders, remove them from the slide.
  • Save the document to a specified path using the Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
public class RemoveFooter {
    public static void main(String[] args) throws Exception {
        // Create a Presentation object
        Presentation presentation = new Presentation();
        // Load the presentation from a file
        presentation.loadFromFile("Sample2.pptx");
        // Get the first slide
        ISlide slide = presentation.getSlides().get(0);
        // Iterate through the shapes on the slide
        for (int i = slide.getShapes().getCount() - 1; i >= 0; i--) {
            // Check if the shape is a placeholder
            if (slide.getShapes().get(i).getPlaceholder() != null) {
                // Get the placeholder type
                PlaceholderType type = slide.getShapes().get(i).getPlaceholder().getType();
                // If it's a footer placeholder
                if (type == PlaceholderType.FOOTER) {
                    // Remove it from the slide
                    slide.getShapes().removeAt(i);
                }
                // If it's a slide number placeholder
                if (type == PlaceholderType.SLIDE_NUMBER) {
                    // Remove it from the slide
                    slide.getShapes().removeAt(i);
                }
                // If it's a date and time placeholder
                if (type == PlaceholderType.DATE_AND_TIME) {
                    // Remove it from the slide
                    slide.getShapes().removeAt(i);
                }
            }
        }
        // Save the modified presentation to a file
        presentation.saveToFile("RemovedFooter.pptx", FileFormat.PPTX_2016);
        // Dispose of the Presentation object resources
        presentation.dispose();
    }
}

Java: Add, Modify, or Remove Footers in PowerPoint Documents

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