مدیریت هایپرلینکهای ارائه در اندروید
مقدمه
یک هایپرلینک ارجاعی به یک شیء، داده یا مکانی در یک محتوا است. اینها هایپرلینکهای رایج در ارائههای PowerPoint هستند:
- پیوند به وبسایتها درون متنها، اشکال یا رسانهها
- پیوند به اسلایدها
Aspose.Slides برای Android از طریق 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();
}
قالببندی هایپرلینکها
رنگ
با استفاده از ویژگی ColorSource در رابط IHyperlink، میتوانید رنگ هایپرلینکها را تنظیم کرده و همچنین اطلاعات رنگ را از هایپرلینکها دریافت کنید. این قابلیت اولین بار در 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)
این قطعه کد نشان میدهد چگونه یک هایپرلینک به یک اسلاید اضافه کرده و پس از آن tooltip آن را ویرایش کنید:
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 گروهی از اسلایدها هستند؛ ناوبری بهصورت فنی به یک اسلاید خاص اشاره میکند. برای «ناوبری به یک بخش»، معمولاً به اولین اسلاید آن بخش پیوند میزنید.
آیا میتوانم یک هایپرلینک را به عناصر اسلاید اصلی (master) وصل کنم تا در همه اسلایدها کار کند؟
بله. عناصر اسلاید اصلی و طرحبندی از هایپرلینکها پشتیبانی میکنند. این پیوندها در اسلایدهای فرزند ظاهر میشوند و در طول نمایش اسلاید قابل کلیک هستند.
آیا هایپرلینکها هنگام خروجی به PDF، HTML، تصاویر یا ویدیو حفظ میشوند؟
در PDF و HTML بله—لینکها بهطور کلی حفظ میشوند. هنگام خروجی به images و video قابلیت کلیک کردن انتقال نمییابد به دلیل ماهیت آن فرمتها (فریمهای رستر/ویدیو از هایپرلینکها پشتیبانی نمیکنند).