Python द्वारा Java में प्रस्तुति हाइपरलिंक प्रबंधित करें

परिचय

हाइपरलिंक एक ऑब्जेक्ट, डेटा या स्थान का संदर्भ होता है। PowerPoint प्रस्तुतियों में सामान्य हाइपरलिंक हैं:

  • टेक्स्ट, शैप्स या मीडिया में वेबसाइट्स के लिंक
  • स्लाइड्स के लिंक

Aspose.Slides for Python via Java आपको प्रस्तुतियों में हाइपरलिंक से संबंधित कई कार्य करने की अनुमति देता है।

URL हाइपरलिंक जोड़ें

टेक्स्ट में URL हाइपरलिंक जोड़ें

यह Python कोड आपको दिखाता है कि टेक्स्ट में वेबसाइट हाइपरलिंक कैसे जोड़ें:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Presentation, SaveFormat, ShapeType

presentation = Presentation()
try:
    shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, False)
    shape.addTextFrame("Aspose: File Format APIs")

    portion_format = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat()
    portion_format.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    portion_format.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")
    portion_format.setFontHeight(32)

    presentation.save("presentation-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

शेप्स या फ्रेम्स में URL हाइपरलिंक जोड़ें

यह Python via Java नमूना कोड आपको दिखाता है कि शैप में वेबसाइट हाइपरलिंक कैसे जोड़ें:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Presentation, SaveFormat, ShapeType

presentation = Presentation()
try:
    shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50)

    shape.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    shape.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")

    presentation.save("pres-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

मीडिया में URL हाइपरलिंक जोड़ें

Aspose.Slides आपको इमेज, ऑडियो और वीडियो फ़ाइलों में हाइपरलिंक जोड़ने की अनुमति देता है।

यह नमूना कोड आपको एक इमेज में हाइपरलिंक कैसे जोड़ें दिखाता है:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Images, Presentation, SaveFormat, ShapeType

presentation = Presentation()
try:
    # प्रस्तुति में छवि जोड़ता है
    image = Images.fromFile("image.png")
    try:
        picture = presentation.getImages().addImage(image)
    finally:
        image.dispose()
    # पहले जोड़ी गई छवि के आधार पर स्लाइड 1 पर चित्र फ्रेम बनाता है
    picture_frame = presentation.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, picture)

    picture_frame.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    picture_frame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")

    presentation.save("pres-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

यह नमूना कोड आपको ऑडियो फ़ाइल में हाइपरलिंक कैसे जोड़ें दिखाता है:

from pathlib import Path

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Presentation, SaveFormat

presentation = Presentation()
try:
    audio_data = Path("audio.mp3").read_bytes()
    java_audio_data = jpype.JArray(jpype.JByte)(audio_data)
    audio = presentation.getAudios().addAudio(java_audio_data)
    audio_frame = presentation.getSlides().get_Item(0).getShapes().addAudioFrameEmbedded(10, 10, 100, 100, audio)

    audio_frame.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    audio_frame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")

    presentation.save("pres-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

यह नमूना कोड आपको वीडियो में हाइपरलिंक कैसे जोड़ें दिखाता है:

from pathlib import Path

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Presentation, SaveFormat

presentation = Presentation()
try:
    video_data = Path("video.avi").read_bytes()
    java_video_data = jpype.JArray(jpype.JByte)(video_data)
    video = presentation.getVideos().addVideo(java_video_data)
    video_frame = presentation.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 100, 100, video)

    video_frame.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    video_frame.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")

    presentation.save("pres-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

सामग्री-सूची बनाने के लिए हाइपरलिंक का उपयोग करें

चूंकि हाइपरलिंक आपको ऑब्जेक्ट या स्थान का संदर्भ जोड़ने की अनुमति देते हैं, आप उनका उपयोग सामग्री‑सूची बनाने के लिए कर सकते हैं।

यह नमूना कोड आपको हाइपरलिंक के साथ सामग्री‑सूची बनाने का तरीका दिखाता है:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import FillType, Paragraph, Portion, Presentation, SaveFormat, ShapeType

Color = jpype.JClass("java.awt.Color")

presentation = Presentation()
try:
    first_slide = presentation.getSlides().get_Item(0)
    second_slide = presentation.getSlides().addEmptySlide(first_slide.getLayoutSlide())

    content_table = first_slide.getShapes().addAutoShape(ShapeType.Rectangle, 40, 40, 300, 100)
    content_table.getFillFormat().setFillType(FillType.NoFill)
    content_table.getLineFormat().getFillFormat().setFillType(FillType.NoFill)
    content_table.getTextFrame().getParagraphs().clear()

    paragraph = Paragraph()
    paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
    paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
    paragraph.setText("Title of slide 2 .......... ")

    link_portion = Portion()
    link_portion.setText("Page 2")
    link_portion.getPortionFormat().getHyperlinkManager().setInternalHyperlinkClick(second_slide)

    paragraph.getPortions().add(link_portion)
    content_table.getTextFrame().getParagraphs().add(paragraph)

    presentation.save("link_to_slide.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

हाइपरलिंक फ़ॉर्मेट करें

रंग

Hyperlink.setColorSource प्रॉपर्टी के साथ आप हाइपरलिंक का रंग सेट कर सकते हैं और हाइपरलिंक से रंग जानकारी प्राप्त कर सकते हैं। यह सुविधा PowerPoint 2019 में पहली बार प्रस्तुत की गई थी, इसलिए इस प्रॉपर्टी में होने वाले परिवर्तन पुराने PowerPoint संस्करणों पर लागू नहीं होते।

यह नमूना कोड एक ही स्लाइड में विभिन्न रंगों वाले हाइपरलिंक जोड़ने का उदाहरण दर्शाता है:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import FillType, Hyperlink, HyperlinkColorSource, Presentation, SaveFormat, ShapeType

Color = jpype.JClass("java.awt.Color")

presentation = Presentation()
try:
    colored_link_shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 450, 50, False)
    colored_link_shape.addTextFrame("This is a sample of colored hyperlink.")
    portion_format = colored_link_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat()
    portion_format.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    portion_format.getHyperlinkClick().setColorSource(HyperlinkColorSource.PortionFormat)
    portion_format.getFillFormat().setFillType(FillType.Solid)
    portion_format.getFillFormat().getSolidFillColor().setColor(Color.RED)

    default_link_shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 450, 50, False)
    default_link_shape.addTextFrame("This is a sample of usual hyperlink.")
    default_link_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setHyperlinkClick(Hyperlink("https://www.aspose.com/"))

    presentation.save("presentation-out-hyperlink.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

प्रेजेंटेशन से हाइपरलिंक हटाएँ

टेक्स्ट से हाइपरलिंक हटाएँ

यह Python कोड आपको दिखाता है कि प्रस्तुति स्लाइड में टेक्स्ट से हाइपरलिंक कैसे हटाएँ:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Presentation, SaveFormat, AutoShape

presentation = Presentation("presentation.pptx")
try:
    slide = presentation.getSlides().get_Item(0)
    for shape in slide.getShapes():
        if isinstance(shape, AutoShape):
            text_frame = shape.getTextFrame()
            if text_frame is not None:
                for paragraph in text_frame.getParagraphs():
                    for portion in paragraph.getPortions():
                        portion.getPortionFormat().getHyperlinkManager().removeHyperlinkClick()

    presentation.save("pres-removed-hyperlinks.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

शेप्स या फ्रेम्स से हाइपरलिंक हटाएँ

यह Python कोड आपको दिखाता है कि प्रस्तुति स्लाइड में शैप से हाइपरलिंक कैसे हटाएँ:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Presentation, SaveFormat

presentation = Presentation("presentation.pptx")
try:
    slide = presentation.getSlides().get_Item(0)
    for shape in slide.getShapes():
        shape.getHyperlinkManager().removeHyperlinkClick()
    presentation.save("pres-removed-hyperlinks.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

परिवर्तनीय हाइपरलिंक

Hyperlink क्लास परिवर्तनीय है। इस क्लास के साथ आप निम्नलिखित प्रॉपर्टीज़ के मान बदल सकते हैं:

यह कोड स्निपेट दिखाता है कि स्लाइड में हाइपरलिंक कैसे जोड़ें और बाद में उसके टूलटिप को संपादित करें:

import jpype
import asposeslides

if not jpype.isJVMStarted():
    jpype.startJVM()

from asposeslides.api import Hyperlink, Presentation, SaveFormat, ShapeType

presentation = Presentation()
try:
    shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, False)
    shape.addTextFrame("Aspose: File Format APIs")

    portion_format = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat()
    portion_format.setHyperlinkClick(Hyperlink("https://www.aspose.com/"))
    portion_format.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs")
    portion_format.setFontHeight(32)

    # पहले ही जोड़े गए हाइपरलिंक के टूलटिप को बदलता है
    portion_format.getHyperlinkClick().setTooltip("Aspose: the File Format APIs")

    presentation.save("presentation-out.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

HyperlinkQueries में समर्थित प्रॉपर्टीज़

आप प्रस्तुति, स्लाइड या टेक्स्ट से HyperlinkQueries तक पहुंच सकते हैं, जहाँ हाइपरलिंक परिभाषित है।

HyperlinkQueries क्लास निम्नलिखित मेथड्स और प्रॉपर्टीज़ को सपोर्ट करता है:

अक्सर पूछे जाने वाले प्रश्न

मैं केवल स्लाइड नहीं, बल्कि “सेक्शन” या सेक्शन की पहली स्लाइड पर नेविगेशन कैसे बना सकता हूँ?

PowerPoint में सेक्शन स्लाइडों का समूह होते हैं; नेविगेशन तकनीकी रूप से किसी विशिष्ट स्लाइड को लक्षित करता है। “सेक्शन पर नेविगेट” करने के लिए आप सामान्यतः उसकी पहली स्लाइड से लिंक बनाते हैं।

क्या मैं मास्टर स्लाइड तत्वों पर हाइपरलिंक लगा सकता हूँ ताकि वह सभी स्लाइड पर काम करे?

हाँ। मास्टर स्लाइड और लेआउट तत्व हाइपरलिंक का समर्थन करते हैं। ऐसे लिंक चाइल्ड स्लाइड्स पर दिखाई देंगे और स्लाइडशो के दौरान क्लिक‑योग्य होंगे।

क्या हाइपरलिंक PDF, HTML, इमेज या वीडियो में एक्सपोर्ट करने पर संरक्षित रहते हैं?

PDF और HTML में हाइपरलिंक सामान्यतः संरक्षित रहते हैं। जब आप इमेज और वीडियो में एक्सपोर्ट करते हैं, तो क्लिक‑योग्यता नहीं रहती क्योंकि उन फॉर्मेट्स में (रास्टर फ्रेम/वीडियो) हाइपरलिंक समर्थित नहीं होते।