LoginSignup
0
0

More than 5 years have passed since last update.

Java PowerPoint転送画像、PDF、XPS、SVGなどのフォーマットファイル

Posted at

この文章は、Javaアプリケーションでは、PowerPointにおける画像、PDF、XPS、SVGなどのフォーマットに変換する方法を紹介します。
コンポーネントを使用: Free Spire.Presentation for Java
コンポーネント概要: Free Spire.Presentation for Java 1つの無料Java PowerPointのコンポーネントで、豊富なフォーマット変換をサポートして、例えばPPTとPPECのフォーマットを互いに回転して、PPT / PPECは画像、PDF、XPSとSVGなどを回転します。
以下のコードを使用する前に、Free Spire.Presentation for Java ダウンロードして解凍する必要があり、それからibフォルダからアプリケーションにjaをインポートします。

PowerPoint転送画像
これによりISlide.SaveAsImage()、PowerPointドキュメントや指定スライドを画像に変換することができます。

import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public class PPTToImage {
    public static void main(String[] args) throws Exception {
        // PPTをロードする
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Input.pptx");

        //画像に保存
        for (int i = 0; i < ppt.getSlides().getCount(); i++) {
            BufferedImage image = ppt.getSlides().get(i).saveAsImage();
            String fileName = "output" + "/" + String.format("ToImage-%1$s.png", i);
            ImageIO.write(image, "PNG",new File(fileName));
        }
        ppt.dispose();
    }
}

PowerPoint回転PDF、XPSなど
通過するPresentation.saveToFile(string filepath, FileFormat fileformat),PPT、Pptx 2007、Pptx 2013、Ppsx 2007、Ppsx 2010、Ppsx 2013、PPS、Opsx、XPS、PDF、HTML、TIFFなどのフォーマットを保存することができます。

PPT回転PDFを例:

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class PPTToPDF {

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

        // PPTをロードする
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Input.ppt");

        // PDFに保存
        ppt.saveToFile("ToPDF.pdf", FileFormat.PDF);
    }
}

PowerPoint回転SVG
通過する Presentation.saveToSVG(),PowerPointドキュメントをSVGに変換することができます.


import com.spire.presentation.Presentation;
import java.io.FileOutputStream;
import java.util.ArrayList;

public class PPTToSVG {

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

        // PPTをロードする
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Input.ppt");

        // SVGに保存
        ArrayList<byte[]> svgBytes =(ArrayList<byte[]>) ppt.saveToSVG();
        int count = svgBytes.size();
        int len = svgBytes.size();
        for (int i = 0; i < len; i++)
        {
            byte[] bytes = svgBytes.get(i);
            FileOutputStream stream = new FileOutputStream(String.format("output" + "/" + "ToSVG-%d.svg", i));
            stream.write(bytes);
        }
         ppt.dispose();
    }
}
0
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
0
0