JavaScript でプレゼンテーションのハイパーリンクを管理する
導入
ハイパーリンクは、プレゼンテーションのコンテンツをウェブサイトまたはプレゼンテーション内の場所に接続します。PowerPoint では、ハイパーリンクは主に次の 2 つの目的で使用されます。
- テキスト、図形、またはメディア フレームからウェブサイトを開く。
- 目次などから別のスライドへ移動する。
Aspose.Slides for Node.js via Java を使用すると、これらのリンクを追加し、外観やサウンドを制御し、プロパティを更新し、削除できます。以下の例は、個々の要素のハイパーリンクの操作方法と、プレゼンテーション、スライド、テキスト フレームレベルでハイパーリンクにアクセスする方法を示しています。
Note
無料のオンライン Aspose PowerPoint エディターでプレゼンテーションを編集することもできます。URL ハイパーリンクの追加
テキスト、図形、またはメディア フレームにウェブサイトの URL を割り当てることができます。ハイパーリンクを割り当てる要素によってクリック可能領域が決まります:テキストの一部は選択したテキストにリンクし、図形やフレームはスライドオブジェクト全体にリンクします。
相対ハイパーリンクを含むプレゼンテーションについては、ハイパーリンク ベースの管理 を参照して、ドキュメントレベルのベースを読み取り、変更、またはクリアしてください。
テキストへの URL ハイパーリンクの追加
テキストをウェブサイトにリンクするには、テキスト部分の setHyperlinkClick メソッドに Hyperlink を渡します。以下に示すように、そのテキスト部分だけがクリック可能になります。
const aspose = { slides: require("aspose.slides.via.java") };
const presentation = new aspose.slides.Presentation();
try {
const textShape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 100, 100, 600, 50, false);
textShape.addTextFrame("Aspose: File Format APIs");
const portionFormat = textShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
portionFormat.setHyperlinkClick(new aspose.slides.Hyperlink("https://www.aspose.com/"));
portionFormat.getHyperlinkClick().setTooltip("Explore Aspose file format APIs");
portionFormat.setFontHeight(32);
presentation.save("presentation-out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
図形やメディア フレームへの URL ハイパーリンクの追加
矩形に対して setHyperlinkClick を呼び出すと、全領域がクリック可能になります。setTooltip を使用して、矩形上にカーソルを合わせたときに宛先のヒントを表示させます。これらのメソッドは、画像、音声、動画フレームにも適用できます。
const aspose = { slides: require("aspose.slides.via.java") };
const presentation = new aspose.slides.Presentation();
try {
const shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 100, 100, 600, 50);
shape.setHyperlinkClick(new aspose.slides.Hyperlink("https://www.aspose.com/"));
shape.getHyperlinkClick().setTooltip("Explore Aspose file format APIs");
presentation.save("presentation-out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ハイパーリンクを使用して目次を作成
内部ハイパーリンクを使用すると、読者は目次から特定のスライドへジャンプできます。次の例は、setInternalHyperlinkClick を使用して、最初のスライド上の「Page 2」テキストを2枚目のスライドにリンクしています。
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const firstSlide = presentation.getSlides().get_Item(0);
const secondSlide = presentation.getSlides().addEmptySlide(firstSlide.getLayoutSlide());
const tableOfContents = firstSlide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 40, 40, 300, 100);
tableOfContents.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
tableOfContents.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
tableOfContents.getTextFrame().getParagraphs().clear();
const paragraph = new aspose.slides.Paragraph();
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
paragraph.setText("Title of slide 2 .......... ");
const linkPortion = new aspose.slides.Portion();
linkPortion.setText("Page 2");
linkPortion.getPortionFormat().getHyperlinkManager().setInternalHyperlinkClick(secondSlide);
paragraph.getPortions().add(linkPortion);
tableOfContents.getTextFrame().getParagraphs().add(paragraph);
presentation.save("link_to_slide.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ハイパーリンクの書式設定
リンクされたテキストの色を変更したり、リンクがアクティブになったときにサウンドを再生または停止したり、ホバー時に表示されるツールチップを設定したりできます。
色
Hyperlink の setColorSource メソッドは、ハイパーリンクがプレゼンテーションのハイパーリンク色を使用するか、テキスト部分の書式設定を使用するかを決定します。カスタムテキスト色を適用するには、HyperlinkColorSource.PortionFormat を選択し、部分の塗りつぶし色を設定します。この機能は PowerPoint 2019 で導入されました。古いバージョンではこの設定は適用されません。
この例では、setColorSource により最初のリンクがテキスト部分の赤い塗りつぶしを使用します。二番目のリンクはプレゼンテーションのハイパーリンク色のままです。
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const coloredShape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 100, 100, 450, 50, false);
coloredShape.addTextFrame("This hyperlink uses a custom color.");
const coloredPortionFormat = coloredShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
coloredPortionFormat.setHyperlinkClick(new aspose.slides.Hyperlink("https://www.aspose.com/"));
coloredPortionFormat.getHyperlinkClick().setColorSource(aspose.slides.HyperlinkColorSource.PortionFormat);
coloredPortionFormat.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
coloredPortionFormat.getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "RED"));
const defaultShape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 100, 200, 450, 50, false);
defaultShape.addTextFrame("This hyperlink uses the default color.");
defaultShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setHyperlinkClick(new aspose.slides.Hyperlink("https://www.aspose.com/"));
presentation.save("presentation-out-hyperlink.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
サウンド
ハイパーリンクはアクティブになったときにサウンドを再生したり、既に再生中のサウンドを停止したりできます。以下のメソッドでこれらの動作を設定します。
- Hyperlink.setSound はハイパーリンクに関連付けるオーディオを指定します。
- Hyperlink.setStopSoundOnClick はハイパーリンクがクリックされたときに前のサウンドを停止するかどうかを制御します。
ハイパーリンク サウンドの追加
最初のスライドのボタンは、Hyperlink.setSound を使用して sampleaudio.wav からオーディオを再生します。2 番目のスライドでは別のボタンが Hyperlink.setStopSoundOnClick を使用して再生を停止し、そのスライドにとどまります。
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
const presentation = new aspose.slides.Presentation();
try {
const audioStream = java.newInstanceSync("java.io.FileInputStream", "sampleaudio.wav");
let hyperlinkSound;
try {
hyperlinkSound = presentation.getAudios().addAudio(audioStream);
} finally {
audioStream.close();
}
const firstSlide = presentation.getSlides().get_Item(0);
const playButton = firstSlide.getShapes().addAutoShape(aspose.slides.ShapeType.SoundButton, 100, 100, 100, 50);
playButton.setHyperlinkClick(aspose.slides.Hyperlink.getNextSlide());
if (!playButton.getHyperlinkClick().getStopSoundOnClick() && playButton.getHyperlinkClick().getSound() == null)
{
playButton.getHyperlinkClick().setSound(hyperlinkSound);
}
const secondSlide = presentation.getSlides().addEmptySlide(firstSlide.getLayoutSlide());
const stopButton = secondSlide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 100, 100, 100, 50);
stopButton.setHyperlinkClick(aspose.slides.Hyperlink.getNoAction());
stopButton.getHyperlinkClick().setStopSoundOnClick(true);
presentation.save("hyperlink-sound.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ハイパーリンク サウンドの抽出
以下の例は、前述のプレゼンテーションを開き、最初の図形のハイパーリンクオーディオを getSound と getBinaryData を使用してメモリに読み取ります。
const aspose = { slides: require("aspose.slides.via.java") };
const presentation = new aspose.slides.Presentation("hyperlink-sound.pptx");
try {
if (presentation.getSlides().size() > 0 && presentation.getSlides().get_Item(0).getShapes().size() > 0) {
const hyperlink = presentation.getSlides().get_Item(0).getShapes().get_Item(0).getHyperlinkClick();
const sound = hyperlink == null ? null : hyperlink.getSound();
if (sound != null) {
const audioData = sound.getBinaryData();
console.log("Extracted " + audioData.length + " bytes of hyperlink audio.");
} else {
console.log("The first shape has no hyperlink sound.");
}
} else {
console.log("The presentation has no first slide or shape to inspect.");
}
} finally {
presentation.dispose();
}
ツールチップとインタラクション設定
テキストまたは図形にハイパーリンクを割り当てた後、次の Hyperlink メソッドを呼び出すことができます。
- setTooltip は、ビューアがリンクのヒントとして表示できるテキストを設定します。
- setTargetFrame は、適用可能な場合に親 HTML フレームセット内のターゲットフレームを指定します。
- setHistory は、リンクを有効にしたときに目的地を閲覧済みハイパーリンクのリストに追加するかどうかを制御します。
- setHighlightClick は、クリック時にハイパーリンクが強調表示されるかどうかを制御します。
プレゼンテーションからハイパーリンクを削除
getAnyHyperlinks を使用して、テキスト部分のリンクを含むハイパーリンク コンテナを収集し、変更前に取得します。次の例は、最初のスライドから両方のアクティベーション タイプを削除します。1 つだけ削除したい場合は、removeHyperlinkClick または removeHyperlinkMouseOver のみを呼び出します。クリック アクションを削除してもマウスオーバー対応は削除されません。
const aspose = { slides: require("aspose.slides.via.java") };
const presentation = new aspose.slides.Presentation("pres.pptx");
try {
if (presentation.getSlides().size() > 0) {
const found = presentation.getSlides().get_Item(0).getHyperlinkQueries().getAnyHyperlinks();
const containers = [];
for (let index = 0; index < found.size(); index++) {
containers.push(found.get_Item(index));
}
for (const container of containers) {
container.getHyperlinkManager().removeHyperlinkClick();
container.getHyperlinkManager().removeHyperlinkMouseOver();
}
presentation.save("pres-removed-hyperlinks.pptx", aspose.slides.SaveFormat.Pptx);
} else {
console.log("The presentation has no slides to process.");
}
} finally {
presentation.dispose();
}
無条件に削除する場合は、removeAllHyperlinks が選択したスコープ内の両方のアクティベーション タイプを一度に削除します。マスター、レイアウト、ノートの選択的クリーンアップとカバレッジについては、Report, Sanitize, and Verify Hyperlinks を参照してください。
SmartArt テキストを置き換える前にハイパーリンクをクリア
既存の SmartArt ノードの段落を置き換えると、古いハイパーリンクが残ることがあります。段落は SmartArtNode.getTextFrame で取得します。部分をクリアする前に、ノード形状のテキストフレームで getHyperlinkQueries を呼び出し、戻りオブジェクトで removeAllHyperlinks を実行します。これにより、そのフレーム内のすべてのハイパーリンクが削除され、他の段落のリンクも含まれます。
例では、SmartArtHyperlink.pptx の最初のスライドの 3 番目の図形が SmartArt グラフィックであると想定し、4 番目のノードの最初の段落を置き換えます。このプレゼンテーションでは、ノードの最初の図形がその段落を表示しています。
両方の部分を追加した後、例は getEffective を使用して有効な書式設定を読み取ります。その書式設定上で、getHyperlinkClick は最初の部分の新しいハイパーリンクを返し、2 番目は null を返します。
const aspose = { slides: require("aspose.slides.via.java") };
const presentation = new aspose.slides.Presentation("SmartArtHyperlink.pptx");
try {
const slide = presentation.getSlides().get_Item(0);
const smartArt = slide.getShapes().get_Item(2);
const node = smartArt.getAllNodes().get_Item(3);
const paragraph = node.getTextFrame().getParagraphs().get_Item(0);
node.getShapes().get_Item(0).getTextFrame().getHyperlinkQueries().removeAllHyperlinks();
paragraph.getPortions().clear();
const link = new aspose.slides.Portion("New reference");
link.getPortionFormat().setHyperlinkClick(new aspose.slides.Hyperlink("https://example.com/new"));
paragraph.getPortions().add(link);
const text = new aspose.slides.Portion(" (updated)");
paragraph.getPortions().add(text);
console.log(link.getPortionFormat().getEffective().getHyperlinkClick().getExternalUrl()); // https://example.com/new
console.log(text.getPortionFormat().getEffective().getHyperlinkClick()); // null
} finally {
presentation.dispose();
}
完全なハイパーリンク インベントリの作成
プレゼンテーションを配布する前に、インタラクティブ アクションとウェブ リンクのインベントリを作成します。getAnyHyperlinks はハイパーリンク コンテナを返し、URL 文字列のフラットリストではありません。各コンテナの getHyperlinkClick と getHyperlinkMouseOver を調べます。これらは独立しており、同じコンテナが両方のアクションを持つことがあるため、完全なレポートにはコンテナごとに最大 2 行が必要です。
形状レベルのハイパーリンクだけをスキャンすると、テキスト部分に付随するリンクを見逃す可能性があります。適切なスコープでクエリを実行し、返されたコンテナを保持して後でアクションを更新または削除できるようにします。
プレゼンテーション、スライド、テキスト フレーム スコープのクエリ
HyperlinkQueries クラスは、Presentation.getHyperlinkQueries、BaseSlide.getHyperlinkQueries および TextFrame.getHyperlinkQueries から取得できます。各スコープは同じクエリをサポートします。
- getHyperlinkClicks はクリック アクションを持つコンテナを返します。
- getHyperlinkMouseOvers はマウスオーバー アクションを持つコンテナを返します。
- getAnyHyperlinks はいずれかまたは両方のアクションを持つコンテナを返します。
この例は、図形とそのテキストにクリックとマウスオーバー アクションを割り当て、別のボタンにマクロ アクションを割り当てます。getAnyHyperlinks の返すコンテナ数と各アクティベーション タイプのカウントを比較します。テキスト フレーム クエリはテキスト内のリンクのみをカウントします。囲む図形の独自アクションはスライドとプレゼンテーションのクエリに表示されます。
const aspose = { slides: require("aspose.slides.via.java") };
function printQueryCounts(scope, queries) {
const clickCount = queries.getHyperlinkClicks().size();
const mouseOverCount = queries.getHyperlinkMouseOvers().size();
const anyCount = queries.getAnyHyperlinks().size();
console.log(scope + ": click=" + clickCount + ", mouse-over=" + mouseOverCount + ", any=" + anyCount);
}
const presentation = new aspose.slides.Presentation();
try {
const slide = presentation.getSlides().get_Item(0);
const destination = presentation.getSlides().addEmptySlide(slide.getLayoutSlide());
const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 400, 60);
shape.getTextFrame().setText("Click the text to go to slide 2");
shape.getHyperlinkManager().setExternalHyperlinkClick("https://example.com/");
shape.getHyperlinkClick().setTooltip("Public website");
shape.getHyperlinkManager().setExternalHyperlinkMouseOver("file:///C:/private/report.xlsx");
const portionFormat = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
portionFormat.getHyperlinkManager().setInternalHyperlinkClick(destination);
portionFormat.getHyperlinkManager().setExternalHyperlinkMouseOver("https://example.com/help");
const macroButton = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 120, 200, 60);
macroButton.getHyperlinkManager().setMacroHyperlinkClick("ReviewPresentation");
printQueryCounts("Presentation", presentation.getHyperlinkQueries());
printQueryCounts("Slide 1", slide.getHyperlinkQueries());
printQueryCounts("Text frame", shape.getTextFrame().getHyperlinkQueries());
presentation.save("hyperlink-audit-input.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
この例では、プレゼンテーションとスライドのクエリはそれぞれクリックコンテナが 3、マウスオーバーコンテナが 2、いずれかのアクションを持つコンテナが 3 を報告します。テキストフレーム クエリは各カテゴリで 1 コンテナを報告します。
アクションと宛先の分類
Hyperlink.getActionType を使用して、宛先を解釈する前にアクションを判定します。HyperlinkActionType の値はウェブ ナビゲーション以上のものをカバーします。
| Values | Meaning for an audit |
|---|---|
Hyperlink |
外部ハイパーリンク。URL とそのスキームを確認してください。 |
JumpSpecificSlide |
特定のスライドへの内部ナビゲーション。 |
JumpFirstSlide, JumpPreviousSlide, JumpNextSlide, JumpLastSlide, JumpLastViewedSlide |
スライドショーコンテキストで解決される組み込みのスライドショーナビゲーション。 |
JumpEndShow, StartCustomSlideShow |
現在のショーを終了するか、カスタムショーを開始します。 |
StartMacro |
マクロを実行します。 |
StartProgram |
プログラムを起動します。 |
OpenFile, OpenPresentation |
ファイルまたは別のプレゼンテーションを開きます。Web URL とは別に確認してください。 |
StartStopMedia |
メディア再生を開始または停止します。 |
NoAction, Unknown |
ナビゲーションアクションなし、またはレビューが必要な不明なアクション。 |
getExternalUrl から外部の宛先を読み取り、getTargetSlide から特定の内部宛先を取得します。内部アクションや組み込みコマンドには外部 URL がない場合があります。空の URL はコンテナにアクションがないことを意味しません。getExternalUrlOriginal が正規化された URL と異なる場合はその値を保持し、利用可能な場合は getTooltip が返すツールチップも含めます。
ハイパーリンクのレポート、サニタイズ、検証
この例は、前の例のプレゼンテーションを開き、アクションごとに JSON レコードを 1 件ずつ書き込みます。getAnyHyperlinks を使用して普通のスライド、マスター、レイアウト、ノート、および存在する場合はノートと配布資料マスターのコンテナを収集します。参照等価性を使用して各コンテナを一度だけカウントし、以下のポリシーを適用し、保存したプレゼンテーションを再度開いてクリックとマウスオーバーの両方のアクションを確認します。
レポートは 1 ベースのスライドインデックスと、利用可能な場合は getSlideId を記録します。getSlide はサポートされるコンテナの所有スライドを提供します。マスター、レイアウト、ノートには通常のスライドインデックスがなく、スコープで識別されます。形状コンテナとテキスト部分の書式コンテナは別々にラベル付けされ、他のコンテナタイプはランタイム型名を保持します。各コンテナにはローカルレポート ID が付与され、2 つのアクションを相関付けできます。レポートはアクションタイプを HyperlinkActionType 列挙型で定義された整数定数として保存します。
この意図的に制限的なアプリケーション ポリシーは、絶対 HTTPS URL と有効な内部スライドターゲットのみを許可します。マクロ、プログラム、ファイル アクション、その他のスライドショー アクション、未知のアクション、その他の URL スキームは拒否されます。これらの拒否はポリシー判断であり、Aspose.Slides の安全性判断ではありません。HTTPS だけでは信頼を確立できないため、ホスト許可リストやその他のチェックをアプリケーションに追加してください。元の URL と正規化された外部 URL の両方がチェックされます。例はリンクをたどったりアクションを実行したりせずにメタデータを監査します。
修正のために、コンテナの getHyperlinkManager は setExternalHyperlinkClick、removeHyperlinkClick、removeHyperlinkMouseOver をサポートします。ここでは、禁止された外部クリックリンクを固定の HTTPS ランディングページに置き換え、その他の禁止クリックと禁止マウスオーバー アクションは個別に削除します。replaceExternalClicks を false に設定すると、すべてのポリシー違反が削除されます。デプロイ前にアプリケーション所有の置換ページを選択してください。
レポートのエクスポート フラグは保守的な PDF レビュー ポリシーを使用します: マウスオーバー アクションと外部リンクや特定スライドジャンプ以外のすべてを潜在的にサポート外としてフラグします。これはレビューのヒントであり、機能テストやフラグが付いていないリンクがエクスポートで残る保証ではありません。サポートされる PDF と HTML エクスポートは、アクション、エクスポートオプション、ビューアに応じてハイパーリンクを保持できる場合があります。ラスタ images と video はインタラクティブ ハイパーリンクを保持できないため、これらの出力の監査時にはすべてのアクションにフラグを付けます。
const aspose = { slides: require("aspose.slides.via.java") };
const java = require("java");
const fs = require("fs");
function slideIndex(presentation, slide) {
if (slide == null) return null;
for (let index = 0; index < presentation.getSlides().size(); index++) {
if (presentation.getSlides().get_Item(index).equals(slide)) return index + 1;
}
return null;
}
function isHttps(value) {
if (value == null || value.length === 0) return false;
try {
const uri = java.newInstanceSync("java.net.URI", value);
const scheme = uri.getScheme();
return uri.isAbsolute() && scheme != null && scheme.toLowerCase() === "https" && uri.getHost() != null;
} catch (exception) {
return false;
}
}
function policyViolation(link) {
if (link == null) return null;
if (link.getActionType() === aspose.slides.HyperlinkActionType.JumpSpecificSlide) {
return link.getTargetSlide() == null ? "Missing target slide" : null;
}
if (link.getActionType() !== aspose.slides.HyperlinkActionType.Hyperlink) return "Action is not allowed";
if (!isHttps(link.getExternalUrl())) return "Normalized URL is not absolute HTTPS";
const original = link.getExternalUrlOriginal();
if (original != null && original.length > 0 && !isHttps(original)) return "Original URL is not absolute HTTPS";
return null;
}
function collectContainers(presentation) {
const found = [];
function addQueries(queries) {
const containers = queries.getAnyHyperlinks();
for (let index = 0; index < containers.size(); index++) {
found.push(containers.get_Item(index));
}
}
function addScope(slide) {
if (slide != null) addQueries(slide.getHyperlinkQueries());
}
addQueries(presentation.getHyperlinkQueries());
for (let index = 0; index < presentation.getMasters().size(); index++) {
addScope(presentation.getMasters().get_Item(index));
}
for (let index = 0; index < presentation.getLayoutSlides().size(); index++) {
addScope(presentation.getLayoutSlides().get_Item(index));
}
for (let index = 0; index < presentation.getSlides().size(); index++) {
addScope(presentation.getSlides().get_Item(index).getNotesSlideManager().getNotesSlide());
}
addScope(presentation.getMasterNotesSlideManager().getMasterNotesSlide());
addScope(presentation.getMasterHandoutSlideManager().getMasterHandoutSlide());
const seen = java.newInstanceSync("java.util.IdentityHashMap");
const unique = [];
for (const container of found) {
if (!seen.containsKey(container)) {
seen.put(container, true);
unique.push(container);
}
}
return unique;
}
function addRow(rows, presentation, link, activation, container, containerId) {
if (link == null) return;
const ownerSlide = java.instanceOf(container, "com.aspose.slides.ISlideComponent") ? container.getSlide() : null;
const targetSlide = link.getTargetSlide();
const violation = policyViolation(link);
const ownerType = java.instanceOf(container, "com.aspose.slides.IShape") ? "Shape" : java.instanceOf(container, "com.aspose.slides.IPortionFormat") ? "Text portion" : container.getClass().getSimpleName();
const ordinaryAction = link.getActionType() === aspose.slides.HyperlinkActionType.Hyperlink || link.getActionType() === aspose.slides.HyperlinkActionType.JumpSpecificSlide;
rows.push({
ContainerId: containerId,
SlideIndex: slideIndex(presentation, ownerSlide),
SlideId: ownerSlide == null ? null : ownerSlide.getSlideId(),
Scope: ownerSlide == null ? null : ownerSlide.getClass().getSimpleName(),
OwnerType: ownerType,
Activation: activation,
ActionType: link.getActionType(),
ExternalUrl: link.getExternalUrl(),
TargetSlideIndex: slideIndex(presentation, targetSlide),
TargetSlideId: targetSlide == null ? null : targetSlide.getSlideId(),
Tooltip: link.getTooltip(),
OriginalExternalUrl: link.getExternalUrlOriginal() === link.getExternalUrl() ? null : link.getExternalUrlOriginal(),
PotentiallyUnsafe: violation != null,
PolicyViolation: violation,
TargetExport: "PDF",
PotentiallyUnsupportedByExport: activation === "mouse-over" || !ordinaryAction
});
}
const replaceExternalClicks = true;
const replacementUrl = "https://example.com/blocked-link";
const presentation = new aspose.slides.Presentation("hyperlink-audit-input.pptx");
try {
const containers = collectContainers(presentation);
const rows = [];
for (let index = 0; index < containers.length; index++) {
const container = containers[index];
addRow(rows, presentation, container.getHyperlinkClick(), "click", container, index + 1);
addRow(rows, presentation, container.getHyperlinkMouseOver(), "mouse-over", container, index + 1);
}
const json = JSON.stringify(rows, null, 2);
fs.writeFileSync("hyperlink-audit.json", json, "utf8");
for (const container of containers) {
const click = container.getHyperlinkClick();
if (policyViolation(click) != null) {
if (replaceExternalClicks && click.getActionType() === aspose.slides.HyperlinkActionType.Hyperlink) {
container.getHyperlinkManager().setExternalHyperlinkClick(replacementUrl);
} else {
container.getHyperlinkManager().removeHyperlinkClick();
}
}
if (policyViolation(container.getHyperlinkMouseOver()) != null) {
container.getHyperlinkManager().removeHyperlinkMouseOver();
}
}
presentation.save("hyperlink-sanitized.pptx", aspose.slides.SaveFormat.Pptx);
const reopened = new aspose.slides.Presentation("hyperlink-sanitized.pptx");
try {
const remainingContainers = collectContainers(reopened);
let violations = 0;
for (const container of remainingContainers) {
if (policyViolation(container.getHyperlinkClick()) != null) violations++;
if (policyViolation(container.getHyperlinkMouseOver()) != null) violations++;
}
console.log("Audit rows: " + rows.length + "; prohibited actions after reopening: " + violations);
if (violations !== 0) {
console.log("Verification failed: do not distribute the saved presentation.");
}
} finally {
reopened.dispose();
}
} finally {
presentation.dispose();
}
上記で作成した入力で、レポートには 5 行のアクションが含まれます。ファイルのマウスオーバーリンクとマクロクリックは削除され、HTTPS リンクと内部スライド ナビゲーションは残ります。検証は禁止アクションを 0 件と出力します。禁止された外部クリック URL を含む入力は置換ブランチも実行します。許可されたクリックと禁止されたマウスオーバーを持つコンテナはクリックアクションを保持します。
この選択的クリーンアップは、removeAllHyperlinks とは異なり、ポリシーに関係なく選択したスコープ全体の両方のアクティベーション タイプを削除します。ここでの検証はハイパーリンク アクションのみをチェックし、埋め込み VBA プロジェクト、OLE オブジェクト、その他のアクティブ コンテンツの削除や、エクスポートされた PDF または HTML ファイルの検証は行いません。
よくある質問
セクションまたはその最初のスライドにリンクするにはどうすればよいですか?
PowerPoint のセクションはスライドをグループ化しますが、内部ハイパーリンクは個々のスライドを対象とします。セクションへのナビゲーションを作成するには、そのセクションの最初のスライドにリンクしてください。
マスタースライドの要素にハイパーリンクを付けて、すべてのスライドで機能させることはできますか?
はい。マスタースライドおよびレイアウト要素はハイパーリンクをサポートしています。これらの要素に付けたリンクは、対応するマスターまたはレイアウトを使用するスライドのスライドショー中に利用可能になります。
PDF、HTML、画像、またはビデオにエクスポートする際にハイパーリンクは保持されますか?
サポートされる PDF と HTML エクスポートはハイパーリンクを保持できる場合がありますが、ラスタ画像とビデオは保持できません。エクスポート時の考慮事項については、ハイパーリンクのレポート、サニタイズ、検証 を参照してください。