日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

本文介紹了如何使用PDFBox創(chuàng)建鏈接,我可以單擊該鏈接轉(zhuǎn)到同一文檔中的另一個(gè)頁(yè)面的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問題描述

我正在嘗試使用PDFBox創(chuàng)建一個(gè)鏈接,我可以單擊該鏈接轉(zhuǎn)到同一文檔中的另一個(gè)頁(yè)面。

從這個(gè)問題(How to use PDFBox to create a link that goes to *previous view*?)我知道這應(yīng)該很容易做到,但是當(dāng)我嘗試這樣做時(shí),我得到了這個(gè)錯(cuò)誤:在線程”main”java.lang.IlLegalArgumentException:GoTo操作的目標(biāo)必須是頁(yè)面字典對(duì)象

我正在使用以下代碼:

//Loading an existing document consisting of 3 empty pages.
    File file = new File("C:\Users\Student\Documents\MyPDF\Test_doc.pdf");
    PDDocument document = PDDocument.load(file);
    PDPage page = document.getPage(1);

    PDAnnotationLink link         = new PDAnnotationLink();
    PDPageDestination destination = new PDPageFitWidthDestination();
    PDActionGoTo action           = new PDActionGoTo();

    destination.setPageNumber(2);
    action.setDestination(destination);
    link.setAction(action);
    link.setPage(page);

我正在使用PDFBox 2.0.13,有人能給我一些指導(dǎo)嗎?我哪里做錯(cuò)了?

感謝所有答案。

推薦答案

首先,對(duì)于本地鏈接(“我可以單擊以轉(zhuǎn)到同一文檔中的另一頁(yè)”),destination.setPageNumber是錯(cuò)誤的使用方法,cf。其Java文檔:

/**
 * Set the page number for a remote destination. For an internal destination, call 
 * {@link #setPage(PDPage) setPage(PDPage page)}.
 *
 * @param pageNumber The page for a remote destination.
 */
public void setPageNumber( int pageNumber )

因此,替換

destination.setPageNumber(2);

destination.setPage(document.getPage(2));

此外,您忘記為鏈接設(shè)置矩形區(qū)域,并且忘記將鏈接添加到頁(yè)面批注。

全部:

PDPage page = document.getPage(1);

PDAnnotationLink link         = new PDAnnotationLink();
PDPageDestination destination = new PDPageFitWidthDestination();
PDActionGoTo action           = new PDActionGoTo();

destination.setPage(document.getPage(2));
action.setDestination(destination);
link.setAction(action);
link.setPage(page);

link.setRectangle(page.getMediaBox());
page.getAnnotations().add(link);

(AddLink測(cè)試testAddLinkToMwb_I_201711)

這篇關(guān)于如何使用PDFBox創(chuàng)建鏈接,我可以單擊該鏈接轉(zhuǎn)到同一文檔中的另一個(gè)頁(yè)面的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,

分享到:
標(biāo)簽:創(chuàng)建 單擊 如何使用 文檔 轉(zhuǎn)到 鏈接 頁(yè)面
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定