page 109

Embed a Zip File in PowerPoint in Java

2021-08-10 07:43:37 Written by Koohji

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 convert shapes and SmartArt graphics in Excel to Image in C# using Spire.XLS for .NET.

The input Excel file:

Convert Shapes and SmartArt in Excel to Image in C#, VB.NET

C#
using Spire.Xls;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;

namespace Convert_Shapes_and_SmartArt_to_Image
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook object
            Workbook workbook = new Workbook();
            //Load the Excel file
            workbook.LoadFromFile("Sample.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Create a SaveShapeTypeOption object
            SaveShapeTypeOption shapelist = new SaveShapeTypeOption();
            //Save shapes and SmartArt graphics in the worksheet to images
            List images = sheet.SaveShapesToImage(shapelist);

            //Save images to file
            int index = 0;
            foreach (Image img in images)
            {
                img.Save("Image/" + "toImage" + index + ".Png", ImageFormat.Png);
                index++;
            }
        }
    }
}
VB.NET
Imports Spire.Xls
Imports System.Collections.Generic
Imports System.Drawing.Imaging

Namespace Convert_Shapes_and_SmartArt_to_Image
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a Workbook object
            Dim workbook As Workbook = New Workbook()
            'Load the Excel file
            workbook.LoadFromFile("Sample.xlsx")

            'Get the first worksheet
            Dim sheet As Worksheet = workbook.Worksheets(0)

            'Create a SaveShapeTypeOption object
            Dim shapelist As SaveShapeTypeOption = New SaveShapeTypeOption()
            'Save shapes and SmartArt graphics in the worksheet to images
            Dim images As List(Of Bitmap) = sheet.SaveShapesToImage(shapelist)

            'Save images to file
            Dim index As Integer = 0

            For Each img As Image In images
                img.Save("Image/" & "toImage" & index & ".Png", ImageFormat.Png)
                index += 1
            Next
        End Sub
    End Class
End Namespace

Converted images:

Convert Shapes and SmartArt in Excel to Image in C#, VB.NET

This article demonstrates how to verify if a Word document is password protected or not using Spire.Doc for Java.

The following image shows that the input Word document is protected with password:

Verify If a Word Document is Password Protected in Java

import com.spire.doc.Document;

public class DetectIfWordIsPasswordProtected {
    public static void main(String []args){
        //Detect if the Word document is password protected
        boolean isPasswordProtected = Document.isPassWordProtected("C:\\Users\\Administrator\\Desktop\\Sample.docx");
        if(isPasswordProtected)
        {
            System.out.println("The document is password protected.");
        }
        else
        {
            System.out.println("The document is not password protected.");
        }
    }
}

Output:

Verify If a Word Document is Password Protected in Java

page 109

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details