LoginSignup
1
0

JavaでPowerPointドキュメントの背景色と背景画像を設定する方法

Last updated at Posted at 2022-03-11

PowerPointドキュメントを作成する場合、ドキュメントをより美しく見せるために、通常、人々はドキュメントの背景色また背景画像を設定します。この記事では、無料のJava PowerPointコンポーネントであるFree Spire.Presentation for Javaを使用して、JavaアプリケーションでPowerPointの単色の背景色、グラデーションの背景色、背景画像を設定する方法を紹介します。

単色またはグラデーションの背景色を設定する

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

import java.awt.*;

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

        //PowerPointドキュメントをロードする
        Presentation ppt = new Presentation();
        ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

        //スライドの数を取得する
        int slideCount = ppt.getSlides().getCount();

        ISlide slide = null;

        //スライドを繰り返し、各スライドに単色の背景色またはグラデーションの背景色を設定する
        for(int i = 0; i < slideCount;i++) {
            slide = ppt.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);

            //単色の背景色を設定する
            /*slide.getSlideBackground().getFill().setFillType(FillFormatType.SOLID);
            slide.getSlideBackground().getFill().getSolidColor().setColor(Color.PINK);*/

            //グラデーションの背景色を設定する
        slide.getSlideBackground().getFill().setFillType(FillFormatType.GRADIENT);
        slide.getSlideBackground().getFill().getGradient().getGradientStops().append(0, Color.WHITE);
        slide.getSlideBackground().getFill().getGradient().getGradientStops().append(1, Color.PINK);
        }

        //ドキュメントを保存する
        ppt.saveToFile("BackgroundColor.pptx", FileFormat.PPTX_2013);
    }
}

単色の背景色にした結果:
01.png

グラデーションの背景色にした結果:
02.png

背景画像を設定する

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.drawing.BackgroundType;
import com.spire.presentation.drawing.FillFormatType;

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

        Presentation ppt = new Presentation();
        ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

        int slideCount = ppt.getSlides().getCount();
        ISlide slide = null;

        for(int i = 0; i < slideCount;i++) {
            slide = ppt.getSlides().get(i);
            slide.getSlideBackground().setType(BackgroundType.CUSTOM);
            slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
            slide.getSlideBackground().getFill().getPictureFill().getPicture().setUrl((new java.io.File("C:\\Users\\Administrator\\Desktop\\bkg.jpg")).getAbsolutePath());
        }

        ppt.saveToFile("BackgroundImage.pptx", FileFormat.PPTX_2013);
    }
}

03.png

今回のPowerPointドキュメントの背景色と背景画像を設定する方法はこれで終わります、最後まで読んでいただきありがとうございます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0