The slide master in PowerPoint preserves some fixed styles, such as background image, title and theme color, which can be inherited by other slides. This article demonstrates how to customize the slide masters in a PowerPoint file and apply them to different slides using Spire.Presentation for Java.

Apply One Slide Master in PowerPoint

import com.spire.presentation.*;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.IImageData;
import com.spire.presentation.drawing.PictureFillType;

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


public class ModifyAndApplySlideMaster {

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

        //create a Presentation object and specify the slide size
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //get the first slide master
        IMasterSlide masterSlide = presentation.getMasters().get(0);

        //set the background image of the slide master
        String backgroundPic = "C:/Users/Administrator/Desktop/bg.jpg";
        BufferedImage image = ImageIO.read(new FileInputStream(backgroundPic));
        IImageData imageData = presentation.getImages().append(image);
        masterSlide.getSlideBackground().setType(BackgroundType.CUSTOM);
        masterSlide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
        masterSlide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        masterSlide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);

        //add an image (company logo) to slide master
        String logo = "C:/Users/Administrator/Desktop/logo.png";
        image = ImageIO.read(new FileInputStream(logo));
        imageData = presentation.getImages().append(image);
        IEmbedImage imageShape = masterSlide.getShapes().appendEmbedImage(ShapeType.RECTANGLE,imageData,new Rectangle2D.Float(40,40,200,60));
        imageShape.getLine().setFillType(FillFormatType.NONE);

        //add some text (company name) to slide master
        IAutoShape textShape = masterSlide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float((float) presentation.getSlideSize().getSize().getWidth()-200,(float) presentation.getSlideSize().getSize().getHeight()-60,200,30));//Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(ppt.SlideSize.Size.Width-200, ppt.SlideSize.Size.Height-60, 200, 30));
        textShape.getTextFrame().setText("Chengdu E-iceblue Co., Ltd.");
        textShape.getTextFrame().getTextRange().setFontHeight(15f);
        textShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        textShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.blue);
        textShape.getTextFrame().getTextRange().getParagraph().setAlignment(TextAlignmentType.CENTER);
        textShape.getFill().setFillType(FillFormatType.NONE);
        textShape.getLine().setFillType(FillFormatType.NONE);

        //append a new slide
        presentation.getSlides().append();

        //save to file
        presentation.saveToFile("ModifySlideMaster.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}

Modify and Apply Slide Maters in PowerPoint in Java

Apply Multiple Slide Maters in PowerPoint

import com.spire.presentation.*;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.IImageData;
import com.spire.presentation.drawing.PictureFillType;

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

public class CreateAndApplyMultiSlideMasters {

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

        //create a Presentation object and specify the slide size
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //add four new slides to the presentation 
        for (int i = 0; i < 4; i++)
        {
            presentation.getSlides().append();
        }

        //get the first slide master
        IMasterSlide first_master = presentation.getMasters().get(0);

        //create another slide master based on the first one 
        presentation.getMasters().appendSlide(first_master);
        IMasterSlide second_master = presentation.getMasters().get(1);

        //set different background images for the two masters
        String pic1 = "C:/Users/Administrator/Desktop/image1.png";
        String pic2 = "C:/Users/Administrator/Desktop/image2.png";
        BufferedImage image = ImageIO.read(new FileInputStream(pic1));
        IImageData imageData = presentation.getImages().append(image);
        first_master.getSlideBackground().setType(BackgroundType.CUSTOM);
        first_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
        first_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        first_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
        image = ImageIO.read(new FileInputStream(pic2));
        imageData = presentation.getImages().append(image);
        second_master.getSlideBackground().setType(BackgroundType.CUSTOM);
        second_master.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
        second_master.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
        second_master.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);

        //apply the first master along with the layout to the first slide
        presentation.getSlides().get(0).setLayout(first_master.getLayouts().get(6));

        //apply the second master along with the layout to the rest slides
        for (int i = 1; i < presentation.getSlides().getCount(); i++)
        {
            presentation.getSlides().get(i).setLayout(second_master.getLayouts().get(6));
        }

        //save to file
        presentation.saveToFile("ApplyMultiMasters.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}

Modify and Apply Slide Maters in PowerPoint in Java

Create Spot Color in PDF in Java

2019-02-26 07:48:36 Written by Koohji

This article will demonstrate how to create spot color to PDF file using Spire.PDF in Java.

import com.spire.pdf.*;
import com.spire.pdf.colorspace.*;
import com.spire.pdf.graphics.*;
import java.awt.*;
import java.awt.geom.Point2D;


public class SpotColor {

    public static void main(String[] args) {

        //Create a PdfDocument instance
        PdfDocument pdf = new PdfDocument();

        //Add a page
        PdfPageBase page = pdf.getPages().add();

        //Define the spot color "MySpotColor" from the built-in color.
        PdfRGBColor pdfRGBColor = new PdfRGBColor(new Color(148,0,211));
        PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor",pdfRGBColor);

        //Apply the spot color while drawing content on the page.
        PdfSeparationColor color = new PdfSeparationColor(cs, 1f);
        PdfSolidBrush brush = new PdfSolidBrush(color);
        page.getCanvas().drawString("Tint=1.0", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(160, 160));

        //Draw pie with spot color(DarkViolet)
        page.getCanvas().drawPie(brush, 148, 200, 60, 60, 360, 360);

        page.getCanvas().drawString("Tint=0.7", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(230, 160));
        color = new PdfSeparationColor(cs, 0.7f);
        brush = new PdfSolidBrush(color);
        page.getCanvas().drawPie(brush, 218, 200, 60, 60, 360, 360);

        page.getCanvas().drawString("Tint=0.4", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(300, 160));
        color = new PdfSeparationColor(cs, 0.4f);
        brush = new PdfSolidBrush(color);
        page.getCanvas().drawPie(brush, 288, 200, 60, 60, 360, 360);

        page.getCanvas().drawString("Tint=0.1", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new Point2D.Float(370, 160));
        color = new PdfSeparationColor(cs, 0.1f);
        brush = new PdfSolidBrush(color);
        page.getCanvas().drawPie(brush, 358, 200, 60, 60, 360, 360);


        //Save the document
        pdf.saveToFile("output/drawContentWithSpotColor.pdf");

    }
}

Effective screenshot after adding spot color in PDF in Java application:

Create Spot Color in PDF in Java

When a PowerPoint presentation is converted to PDF, its document layout and formatting are fixed. Recipients can view the converted document without having Microsoft PowerPoint to be installed, but they can not modify it easily. In this article, we will demonstrate how to convert PowerPoint presentations to PDF in Java using Spire.Presentation for Java library.

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

Convert a Whole PowerPoint Presentation to PDF in Java

The following steps show you how to convert a whole PowerPoint presentation to PDF:

  • Initialize an instance of Presentation class.
  • Load the PowerPoint presentation using Presentation.loadFromFile() method.
  • Save it to PDF using Presentation.saveToFile(filePath, FileFormat.PDF) method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

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

        //Save it as PDF
        ppt.saveToFile("ToPdf1.pdf", FileFormat.PDF);
    }
}

Java: Convert PowerPoint Presentations to PDF

Convert Specific Slide of a PowerPoint Presentation to PDF in Java

The following steps show you how to convert a specific slide of a PowerPoint presentation to PDF:

  • Initialize an instance of Presentation class.
  • Load the PowerPoint presentation using Presentation.loadFromFile() method.
  • Get the desired slide by its index using Presentation.getSlides().get(slideIndex) method.
  • Save it to PDF using ISlide.saveToFile(filePath, FileFormat.PDF) method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;

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

        //Get the second slide
        ISlide slide= ppt.getSlides().get(1);

        //Save the slide to PDF
        slide.saveToFile("ToPdf2.pdf", FileFormat.PDF);
    }
}

Java: Convert PowerPoint Presentations to PDF

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 71