チュートリアル
簡単にライブラリーを使用するためのチュートリアルコレクション
OpenDocument プレゼンテーション ドキュメント形式は、一般的に ODP と呼ばれ、Open Document Format ファイルのファイル拡張子の 1 つです。スライドショー プレゼンテーションのオープンソース表示形式として機能するように設計されています。ドキュメントの書式が維持されるようにするには、ODP ファイルを PDF に変換する必要がある場合があります。この記事では、Spire.Presentation for Java を使用してこの機能を実現する方法を説明します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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.4.5</version>
</dependency>
</dependencies>
Spire.Presentation for Java を使用して ODP を PDF に変換するには、以下の手順に従って簡単かつ迅速に行うことができます。
import com.spire.presentation.*;
public class ODPtoPDF {
public static void main(String[] args) throws Exception {
// Presentationのインスタンスを作成する
Presentation presentation = new Presentation();
// サンプルのODPファイルをロードする
presentation.loadFromFile("サンプル.odp", FileFormat.ODP);
// PDFとして保存する
presentation.saveToFile("output/ODPをPDFに変換.pdf", FileFormat.PDF);
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
画像ファイルは、人々の日常生活で最もよく使われるドキュメントの一形態です。時折、特定のフォルダ内の全ての画像ファイルを取り出し、PowerPoint プレゼンテーション用のスライドに変換する必要が生じます。お客様の要件に応じて、画像をシェイプやスライドの背景に変換することが可能です。この記事では、Spire.Presentation for Java を使用して画像を PowerPoint ドキュメントに変換する方法を示します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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>8.9.4</version>
</dependency>
</dependencies>
PowerPoint の各スライドの背景として画像が変換される場合、それらは移動や拡大縮小ができません。以下は、Spire.Presentation for Java を使用して、画像を PowerPoint ファイルに背景画像として変換する手順です。
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
public class ConvertImagesAsBackground {
public static void main(String[] args) throws Exception {
//Presentationオブジェクトを作成する
Presentation presentation = new Presentation();
//スライドのサイズの種類を設定する
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//デフォルトのスライドを削除する
presentation.getSlides().removeAt(0);
//フォルダーから画像ファイルを取得する
File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
File[] picFiles = directoryPath.listFiles();
//画像をループする
for (int i = 0; i < picFiles.length; i++)
{
//スライドを追加する
ISlide slide = presentation.getSlides().append();
//特定の画像を取得する
String imageFile = picFiles[i].getAbsolutePath();
//画像コレクションに追加する
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(imageFile));
IImageData imageData = presentation.getImages().append(bufferedImage);
//画像をスライドの背景画像として設定する
slide.getSlideBackground().setType(BackgroundType.CUSTOM);
slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
}
//結果文書を保存する
presentation.saveToFile("ImagesToBackground.pptx", FileFormat.PPTX_2013);
}
}
PowerPoint ファイルで画像を移動可能かつサイズ変更可能にしたい場合は、それらを図形として変換することができます。以下は、Spire.Presentation for Java を使用して PowerPoint 文書内の画像を図形に変換する手順です。
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
public class ConvertImageToShape {
public static void main(String[] args) throws Exception {
//Presentationオブジェクトを作成する
Presentation presentation = new Presentation();
//スライドのサイズの種類を設定する
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//デフォルトのスライドを削除する
presentation.getSlides().removeAt(0);
//フォルダーから画像ファイルを取得する
File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
File[] picFiles = directoryPath.listFiles();
//画像をループする
for (int i = 0; i < picFiles.length; i++)
{
//スライドを追加する
ISlide slide = presentation.getSlides().append();
//特定の画像を取得する
String imageFile = picFiles[i].getAbsolutePath();
//画像コレクションに追加する
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(imageFile));
IImageData imageData = presentation.getImages().append(bufferedImage);
//スライドと同じサイズの図形を追加する
IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(0, 0, (float) presentation.getSlideSize().getSize().getWidth(), (float)presentation.getSlideSize().getSize().getHeight()));
//図形を画像で塗りつぶす
shape.getLine().setFillType(FillFormatType.NONE);
shape.getFill().setFillType(FillFormatType.PICTURE);
shape.getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
shape.getFill().getPictureFill().getPicture().setEmbedImage(imageData);
}
//結果文書を保存する
presentation.saveToFile("ImagesToShape.pptx", FileFormat.PPTX_2013);
}
}
もし画像のアスペクト比が 16:9 ではない場合や、標準のスライドサイズでない場合は、画像の実際のサイズに基づいてスライドを作成することができます。これにより、画像が過度に伸びたり圧縮されたりするのを防ぐことができます。以下は、Spire.Presentation for Java を使用してカスタマイズされたスライドサイズで PowerPoint 文書に画像を変換する手順です。
import com.spire.pdf.graphics.PdfGraphicsUnit;
import com.spire.pdf.graphics.PdfUnitConvertor;
import com.spire.presentation.*;
import com.spire.presentation.drawing.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
public class CustomizeSlideSize {
public static void main(String[] args) throws Exception {
//Presentationオブジェクトを作成する
Presentation presentation = new Presentation();
//デフォルトのスライドを削除する
presentation.getSlides().removeAt(0);
//フォルダーから画像ファイルを取得する
File directoryPath = new File("C:\\Users\\Administrator\\Desktop\\Images");
File[] picFiles = directoryPath.listFiles();
//PdfUnitConvertor オブジェクトを作成する
PdfUnitConvertor convertor = new PdfUnitConvertor();
//画像をループする
for (int i = 0; i < picFiles.length; i++)
{
//特定の画像を取得する
String imageFile = picFiles[i].getAbsolutePath();
//画像コレクションに追加する
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(imageFile));
IImageData imageData = presentation.getImages().append(bufferedImage);
//画像の高さと幅をピクセル単位で取得する
int height = imageData.getHeight();
int width = imageData.getWidth();
//ピクセルをポイントに変換する
float widthPoint = convertor.convertUnits(width, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
float heightPoint= convertor.convertUnits(height, PdfGraphicsUnit.Pixel, PdfGraphicsUnit.Point);
//スライドのサイズを設定する
presentation.getSlideSize().setSize(new Dimension((int)widthPoint, (int)heightPoint));
//スライドを追加する
ISlide slide = presentation.getSlides().append();
//画像をスライドの背景画像として設定する
slide.getSlideBackground().setType(BackgroundType.CUSTOM);
slide.getSlideBackground().getFill().setFillType(FillFormatType.PICTURE);
slide.getSlideBackground().getFill().getPictureFill().setFillType(PictureFillType.STRETCH);
slide.getSlideBackground().getFill().getPictureFill().getPicture().setEmbedImage(imageData);
}
//結果文書を保存する
presentation.saveToFile("CustomizeSlideSize.pptx", FileFormat.PPTX_2013);
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
PowerPoint を HTML に変換することで、文書のアクセシビリティとインタラクティビティが最適化されます。PowerPoint のプレゼンテーションを HTML 形式に変換することで、さまざまなプラットフォームやデバイスで簡単に共有することができます。オンラインでスライドを共有するか、ウェブページにシームレスに統合するかに関係なく、PowerPoint を HTML に変換することは素晴らしい選択です。この記事では、Spire.Presentation for Java を使用して PowerPoint ファイルを HTML に変換する方法を示します。
まず、Spire.Presentation for Javaを Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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>8.7.3</version>
</dependency>
</dependencies>
Spire.Presentation for Java を使用すると、PowerPoint ファイルを HTML 形式に変換することができます。詳細な手順は次のとおりです。
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class ToHtml {
public static void main(String[] args) throws Exception {
//Presentationクラスのインスタンスを初期化する
Presentation presentation = new Presentation();
//PowerPointファイルをロードする
presentation.loadFromFile("sample.pptx");
//ファイルをHTML形式で保存する
presentation.saveToFile("ToHtml.html", FileFormat.HTML);
presentation.dispose();
}
}
場合によっては、プレゼンテーション全体ではなく、特定のスライドを HTML に変換する必要があることがあります。そのような場合、Spire.Presentation for Java では、ISlide.saveToFile() メソッドを使用してスライドを HTML 形式に変換することができます。詳細な手順は次のとおりです。
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.ISlide;
public class ConvertSpecificSlideToHtml { public static void main(String[] args) throws Exception {
//Presentationクラスのインスタンスを初期化する
Presentation presentation = new Presentation();
//PowerPointファイルをロードする
presentation.loadFromFile("sample.pptx");
//インデックスで特定のスライドを取得する
ISlide slide = presentation.getSlides().get(1);
//特定のスライドをHTML形式で保存する
slide.saveToFile("SpecificSlideToHtml.html", FileFormat.HTML);
slide.dispose();
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
PowerPoint ドキュメントと比較して、画像ファイルは、特定のソフトウェアを必要とせずに、ほぼすべてのデバイスで開くことができるため、表示しやすくなっています。PowerPoint ドキュメントをさまざまなデバイスで利用できるようにしたい場合、画像に変換することができます。今回は、Spire.Presentation for Java を使用して、Java で PowerPoint ドキュメントをさまざまな画像形式に変換する方法を説明します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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>7.10.1</version>
</dependency>
</dependencies>
PowerPointドキュメントを JPG または PNG 画像に変換する手順は次のとおりです。
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
public class convertPowerPointToPngOrJpg {
public static void main(String []args) throws Exception {
//Presentationクラスのインスタンスを作成する
Presentation presentation = new Presentation();
//PowerPointドキュメントを読み込む
presentation.loadFromFile("C:/Sample.pptx");
//PowerPointドキュメント内の全スライドを循環させる
for(int i = 0; i < presentation.getSlides().getCount(); i++)
{
ISlide slide = presentation.getSlides().get(i);
//各スライドをPNG画像で保存する
BufferedImage image = slide.saveAsImage();
String fileName = String.format("画像-%1$s.png", i);
ImageIO.write(image, "PNG",new File(fileName));
}
}
}
PowerPoint ドキュメントを TIFF 画像に変換する手順は次のとおりです。
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class convertPowerPointToTiff {
public static void main(String []args) throws Exception {
//Presentationクラスのインスタンスを作成する
Presentation presentation = new Presentation();
//PowerPointドキュメントを読み込む
presentation.loadFromFile("C:/Sample.pptx");
//PowerPointドキュメントをTIFF画像に変換する
presentation.saveToFile("TIFF.tiff", FileFormat.TIFF);
}
}
PowerPoint ドキュメントを SVG 画像に変換する手順を説明します。
import com.spire.presentation.Presentation;
import java.io.FileOutputStream;
import java.util.ArrayList;
public class convertPowerPointToSVG {
public static void main(String []args) throws Exception {
//Presentationクラスのインスタンスを作成する
Presentation presentation = new Presentation();
//PowerPointドキュメントを読み込む
presentation.loadFromFile("C:/Sample.pptx");
//PowerPointドキュメントをSVGに変換し、その結果をバイト配列のArrayListに保存する
ArrayList svgBytes =(ArrayList) presentation.saveToSVG();
int len = svgBytes.size();
//ArrayListのバイト配列をループする
for (int i = 0; i < len; i++)
{
//現在のバイト配列を取得する
byte[] bytes = (byte[]) svgBytes.get(i);
//出力ファイル名を指定する
String fileName= String.format("ToSVG-%d.svg", i);
//FileOutputStreamクラスのインスタンスを作成する
FileOutputStream stream = new FileOutputStream(fileName);
//バイト配列をSVGファイルに保存する
stream.write(bytes);
}
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
XPS は固定ページレイアウトを持つファイル書式です。この書式は、ドキュメントの忠実度を維持し、デバイスに依存しないドキュメントの外観を提供することができます。PowerPoint ファイルを既存の形式で印刷したり、他の人に送信したりするには、XPS に変換することができます。この記事では、Spire.Presentation for Java を使用して PowerPoint を XPS に変換する方法を示します。以下に具体的な手順と方法を示します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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>7.8.2</version>
</dependency>
</dependencies>
Spire.Presentation for Java が提供する Presentation.saveToFile(java.lang.String file, FileFormat fileFormat) メソッドは、スライドを XPS ファイル書式として保存します。具体的な手順は次のとおりです。
import com.spire.presentation.*;
public class PPTtoXPS {
public static void main(String[] args) throws Exception{
// Presentationクラスのオブジェクトを作成する
Presentation ppt = new Presentation();
// PowerPointプレゼンテーションをロードする
ppt.loadFromFile("input.pptx");
//ファイルをXPSとして保存する
ppt.saveToFile("ToXPS.xps",FileFormat.XPS);
ppt.dispose();
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。
PowerPoint プレゼンテーションを PDF に変換する場合、ドキュメントのレイアウトとフォーマットは固定されます。受信者は、Microsoft PowerPoint をインストールせずに変換されたドキュメントを表示できますが、勝手に変更することはできません。この記事では、Spire.Presentation for Java を使用して PowerPoint プレゼンテーションを PDF に変換する方法を示します。
まず、Spire.Presentation for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。
<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>7.8.2</version>
</dependency>
</dependencies>
次の手順は、Spire.Presentation for Java を使用して PowerPoint プレゼンテーション全体を PDF に変換する方法を示しています。
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 {
//Presentationクラスのインスタンスを作成する
Presentation ppt = new Presentation();
//PowerPointプレゼンテーションをロードする
ppt.loadFromFile("Sample.pptx");
//ファイルをPDFとして保存する
ppt.saveToFile("ToPdf1.pdf", FileFormat.PDF);
}
}
次の手順は、Spire.Presentation for Java を使用して PowerPoint プレゼンテーションの特定のスライドを PDF に変換する方法を示しています。
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 {
//Presentationクラスのインスタンスを作成する
Presentation ppt = new Presentation();
//PowerPointプレゼンテーションをロードする
ppt.loadFromFile("Sample.pptx");
//2枚目のスライドを取得する
ISlide slide= ppt.getSlides().get(1);
//スライドをPDFとして保存する
slide.saveToFile("ToPdf2.pdf", FileFormat.PDF);
}
}
結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。