Androidでプレゼンテーションのハイパーリンクを管理
ハイパーリンクは、オブジェクトやデータ、あるいは場所への参照です。PowerPoint プレゼンテーションで一般的に使用されるハイパーリンクは次のとおりです:
- テキスト、図形、またはメディア内のウェブサイトへのリンク
- スライドへのリンク
Aspose.Slides for Android via Java を使用すると、プレゼンテーション内のハイパーリンクに関するさまざまなタスクを実行できます。
URL ハイパーリンクの追加
テキストへの URL ハイパーリンクの追加
この Java コードは、テキストにウェブサイトのハイパーリンクを追加する方法を示しています:
Presentation presentation = new Presentation();
try {
IAutoShape shape1 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, false);
shape1.addTextFrame("Aspose: File Format APIs");
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
portionFormat.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
portionFormat.setFontHeight(32);
presentation.save("presentation-out.pptx", SaveFormat.Pptx);
} finally {
if (presentation != null) presentation.dispose();
}
図形またはフレームへの URL ハイパーリンクの追加
この Java のサンプルコードは、図形にウェブサイトのハイパーリンクを追加する方法を示しています:
Presentation pres = new Presentation();
try {
IShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50);
shape.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
shape.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
pres.save("pres-out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
メディアへの URL ハイパーリンクの追加
Aspose.Slides を使用すると、画像、音声、ビデオ ファイルにハイパーリンクを追加できます。
このサンプルコードは、画像 にハイパーリンクを追加する方法を示しています:
Presentation pres = new Presentation();
try {
// プレゼンテーションに画像を追加
IPPImage picture;
IImage image = Images.fromFile("image.png");
try {
picture = pres.getImages().addImage(picture);
} finally {
if (image != null) image.dispose();
}
// 前に追加した画像を基にスライド1に画像フレームを作成
IPictureFrame pictureFrame = pres.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, picture);
pictureFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
pictureFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
pres.save("pres-out.pptx", SaveFormat.Pptx);
} catch(IOException e) {
} finally {
if (pres != null) pres.dispose();
}
このサンプルコードは、音声ファイル にハイパーリンクを追加する方法を示しています:
Presentation pres = new Presentation();
try {
IAudio audio = pres.getAudios().addAudio(Files.readAllBytes(Paths.get("audio.mp3")));
IAudioFrame audioFrame = pres.getSlides().get_Item(0).getShapes().addAudioFrameEmbedded(10, 10, 100, 100, audio);
audioFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
audioFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
pres.save("pres-out.pptx", SaveFormat.Pptx);
} catch(IOException e) {
} finally {
if (pres != null) pres.dispose();
}
このサンプルコードは、ビデオ にハイパーリンクを追加する方法を示しています:
Presentation pres = new Presentation();
try {
IVideo video = pres.getVideos().addVideo(Files.readAllBytes(Paths.get("video.avi")));
IVideoFrame videoFrame = pres.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 100, 100, video);
videoFrame.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
videoFrame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
pres.save("pres-out.pptx", SaveFormat.Pptx);
} catch(IOException e) {
} finally {
if (pres != null) pres.dispose();
}
Tip
[OLE の管理] をご覧ください。ハイパーリンクを使用した目次の作成
ハイパーリンクはオブジェクトや場所への参照を追加できるため、目次の作成に利用できます。
このサンプルコードは、ハイパーリンクを使用して目次を作成する方法を示しています:
Presentation pres = new Presentation();
try {
ISlide firstSlide = pres.getSlides().get_Item(0);
ISlide secondSlide = pres.getSlides().addEmptySlide(firstSlide.getLayoutSlide());
IAutoShape contentTable = firstSlide.getShapes().addAutoShape(ShapeType.Rectangle, 40, 40, 300, 100);
contentTable.getFillFormat().setFillType(FillType.NoFill);
contentTable.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
contentTable.getTextFrame().getParagraphs().clear();
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
paragraph.setText("Title of slide 2 .......... ");
Portion linkPortion = new Portion();
linkPortion.setText("Page 2");
linkPortion.getPortionFormat().getHyperlinkManager().setInternalHyperlinkClick(secondSlide);
paragraph.getPortions().add(linkPortion);
contentTable.getTextFrame().getParagraphs().add(paragraph);
pres.save("link_to_slide.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
ハイパーリンクの書式設定
色
IHyperlink インターフェイスの ColorSource プロパティを使用すると、ハイパーリンクの色を設定したり、ハイパーリンクから色情報を取得したりできます。この機能は PowerPoint 2019 で初めて導入されたため、プロパティに関する変更は古いバージョンの PowerPoint には適用されません。
このサンプルコードは、同じスライドに異なる色のハイパーリンクが追加された操作を示しています:
Presentation pres = new Presentation();
try {
IAutoShape shape1 = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 450, 50, false);
shape1.addTextFrame("This is a sample of colored hyperlink.");
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
portionFormat.getHyperlinkClick().setColorSource(HyperlinkColorSource.PortionFormat);
portionFormat.getFillFormat().setFillType(FillType.Solid);
portionFormat.getFillFormat().getSolidFillColor().setColor(Color.RED);
IAutoShape shape2 = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 450, 50, false);
shape2.addTextFrame("This is a sample of usual hyperlink.");
shape2.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
pres.save("presentation-out-hyperlink.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
プレゼンテーションからハイパーリンクを削除する
テキストからハイパーリンクを削除する
この Java コードは、プレゼンテーション スライドのテキストからハイパーリンクを削除する方法を示しています:
Presentation pres = new Presentation();
try {
ISlide slide = pres.getSlides().get_Item(0);
for (IShape shape : slide.getShapes())
{
IAutoShape autoShape = (IAutoShape)shape;
if (autoShape != null)
{
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs())
{
for (IPortion portion : paragraph.getPortions())
{
portion.getPortionFormat().getHyperlinkManager().removeHyperlinkClick();
}
}
}
}
pres.save("pres-removed-hyperlinks.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
図形またはフレームからハイパーリンクを削除する
この Java コードは、プレゼンテーション スライドの図形からハイパーリンクを削除する方法を示しています:
Presentation pres = new Presentation();
try {
ISlide slide = pres.getSlides().get_Item(0);
for (IShape shape : slide.getShapes())
{
shape.getHyperlinkManager().removeHyperlinkClick();
}
pres.save("pres-removed-hyperlinks.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
可変ハイパーリンク
Hyperlink クラスは可変です。このクラスを使用すると、以下のプロパティの値を変更できます:
- IHyperlink.setTargetFrame(String value)
- IHyperlink.setTooltip(String value)
- IHyperlink.setHistory(boolean value)
- IHyperlink.setHighlightClick(boolean value)
- IHyperlink.setStopSoundOnClick(boolean value)
このコードスニペットは、スライドにハイパーリンクを追加し、後でツールチップを編集する方法を示しています:
Presentation pres = new Presentation();
try {
IAutoShape shape1 = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, false);
shape1.addTextFrame("Aspose: File Format APIs");
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/"));
portionFormat.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs");
portionFormat.setFontHeight(32);
pres.save("presentation-out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
IHyperlinkQueries のサポート プロパティ
プレゼンテーション、スライド、またはハイパーリンクが定義されているテキストから IHyperlinkQueries にアクセスできます。
- IPresentation.getHyperlinkQueries()
- IBaseSlide.getHyperlinkQueries()
- ITextFrame.getHyperlinkQueries()
IHyperlinkQueries クラスは以下のメソッドとプロパティをサポートしています:
- IHyperlinkQueries.getHyperlinkClicks()
- IHyperlinkQueries.getHyperlinkMouseOvers()
- IHyperlinkQueries.getAnyHyperlinks()
- IHyperlinkQueries.removeAllHyperlinks()
FAQ
スライドだけでなく「セクション」やセクションの最初のスライドへ内部ナビゲーションを作成するにはどうすればよいですか?
PowerPoint のセクションはスライドのグループ化です。ナビゲーションは技術的には特定のスライドを対象にするため、セクションへ「移動」したい場合は通常、その最初のスライドへリンクします。
マスタースライドの要素にハイパーリンクを付けて、すべてのスライドで機能させることはできますか?
はい。マスタースライドおよびレイアウト要素はハイパーリンクをサポートします。これらのリンクは子スライドに反映され、スライドショー中にクリック可能です。
PDF、HTML、画像、またはビデオにエクスポートしたときにハイパーリンクは保持されますか?
PDF と HTML では、リンクは一般的に保持されます。画像 や ビデオ にエクスポートする場合、ラスタ画像やビデオフレームはハイパーリンクをサポートしないため、クリック可能性は失われます。