Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接

這篇文章主要為大家展示了Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來看看吧。

創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),青山網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:青山等地區(qū)。青山做網(wǎng)站價(jià)格咨詢:028-86922220

使用工具:Free Spire.Presentation for Java(免費(fèi)版)Jar文件獲取及導(dǎo)入:

方法1:通過官網(wǎng)下載獲取jar包。解壓后將lib文件夾下的Spire.Presentation.jar文件導(dǎo)入Java程序。(如下圖)

Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接

方法2:通過maven倉庫安裝導(dǎo)入。具體安裝教程參見此網(wǎng)頁。

【示例1】添加文本超鏈接

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;

public class TextHyperlink {
  public static void main(String[] args) throws Exception {
    //創(chuàng)建一個(gè)PPT文檔,默認(rèn)包含一張幻燈片
    Presentation presentation = new Presentation();

    //在文檔最后追加一張幻燈片并填充一些內(nèi)容,方便之后添加超鏈接鏈接到此幻燈片
    presentation.getSlides().append();
    Rectangle2D.Double rec = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 255, 120, 500, 280);
    IAutoShape shape = presentation.getSlides().get(1).getShapes().appendShape(ShapeType.RECTANGLE, rec);
    shape.getFill().setFillType(FillFormatType.NONE);
    shape.getLine().setWidth(0);
    ParagraphEx para1 = new ParagraphEx();
    PortionEx tr1 = new PortionEx();
    tr1.setText("這是第二頁!");
    para1.getTextRanges().append(tr1);
    shape.getTextFrame().getParagraphs().append(para1);
    para1.setAlignment(TextAlignmentType.CENTER);
    tr1.getFill().setFillType(FillFormatType.SOLID);
    tr1.getFill().getSolidColor().setColor(Color.blue);
    shape.getTextFrame().getParagraphs().append(new ParagraphEx());

    //在第一張幻燈片上添加形狀
    IAutoShape shape1 = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec);
    shape1.getFill().setFillType(FillFormatType.NONE);
    shape1.getLine().setWidth(0);

    //添加鏈接到網(wǎng)頁的超鏈接
    ParagraphEx para2 = new ParagraphEx();
    PortionEx tr2 = new PortionEx();
    tr2.setText("點(diǎn)擊鏈接到網(wǎng)頁");
    tr2.getClickAction().setAddress("https://www.jianshu.com/");
    para2.getTextRanges().append(tr2);
    shape1.getTextFrame().getParagraphs().append(para2);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());

    //添加鏈接到郵箱地址的超鏈接
    ParagraphEx para3 = new ParagraphEx();
    PortionEx tr3 = new PortionEx();
    tr3.setText("點(diǎn)擊鏈接到郵箱地址");
    tr3.getClickAction().setAddress("mailto:Tina.tang@e-iceblue.com");
    para3.getTextRanges().append(tr3);
    shape1.getTextFrame().getParagraphs().append(para3);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());

    //添加鏈接到其他文檔的超鏈接
    ParagraphEx para4 = new ParagraphEx();
    PortionEx tr4 = new PortionEx();
    tr4.setText("點(diǎn)擊鏈接到其他文檔");
    tr4.getClickAction().setAddress("C:\\Users\\Test1\\Desktop\\月銷售統(tǒng)計(jì)表.xlsx");
    para4.getTextRanges().append(tr4);
    shape1.getTextFrame().getParagraphs().append(para4);
    shape1.getTextFrame().getParagraphs().append(new ParagraphEx());

    //添加超鏈接跳轉(zhuǎn)到其他幻燈片
    ParagraphEx para5 = new ParagraphEx();
    PortionEx tr5 = new PortionEx("點(diǎn)擊跳轉(zhuǎn)到第二張幻燈片");
    ClickHyperlink link = new ClickHyperlink(presentation.getSlides().get(1));
    tr5.setClickAction(link);
    para5.getTextRanges().append(tr5);
    shape1.getTextFrame().getParagraphs().append(para5);

    //保存文檔
    presentation.saveToFile("output/TextHyperlink.pptx", FileFormat.PPTX_2010);
  }
}

添加效果:

Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接

注:需幻燈片放映時(shí)方能顯示超鏈接地址!

【示例2】添加圖片超鏈接

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;

public class ImageHyperlink {
  public static void main(String[] args) throws Exception {
    //創(chuàng)建Presentation對(duì)象
    Presentation presentation = new Presentation();

    //獲取第一張幻燈片
    ISlide slide = presentation.getSlides().get(0);

    //添加圖片到幻燈片
    String imaPath = "C:\\Users\\Test1\\Desktop\\Signature.png";
    Rectangle2D.Float rect = new Rectangle2D.Float(50, 50, 220, 100);
    IEmbedImage image = slide.getShapes().appendEmbedImage(ShapeType.RECTANGLE, imaPath, rect);

    //將圖片形狀的邊線設(shè)置為無
    image.getLine().setFillType(FillFormatType.NONE);

    //添加超鏈接到圖片
    ClickHyperlink hyperlink = new ClickHyperlink("https://www.jianshu.com/u/96431825b792");
    image.setClick(hyperlink);

    //保存文檔
    presentation.saveToFile("output/ImageHyperLink.pptx", FileFormat.PPTX_2013);
  }
}

添加效果:

Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接

注:需幻燈片放映時(shí)方能顯示超鏈接地址!

以上就是關(guān)于Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接的內(nèi)容,如果你們有學(xué)習(xí)到知識(shí)或者技能,可以把它分享出去讓更多的人看到。

分享標(biāo)題:Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接
標(biāo)題鏈接:http://bm7419.com/article24/geihje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、域名注冊(cè)、網(wǎng)站設(shè)計(jì)網(wǎng)頁設(shè)計(jì)公司、商城網(wǎng)站、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司