我有一些包含URL和mailto形式的超鏈接的PDF。現在是否有任何方式或工具(可能是第三方)從PDF中提取超鏈接元信息,如座標,鏈接類型和目標地址。任何幫助,高度讚賞。來自PDF的超鏈接檢測
我已經嘗試使用iText和PDFBox,但沒有大的成功,甚至有些第三方軟件也不能提供我想要的輸出。
我曾嘗試利用iText
PdfReader myReader = new PdfReader("pdf File Path");
PdfDictionary pageDict = myReader.getPageN(1);
PdfArray annots = pageDict.getAsArray(PdfName.ANNOTS);
System.out.println(annots);
ArrayList<String> dests = new ArrayList<String>();
if(annots != null)
{
for(int i=0; i<annots.size(); ++i)
{
PdfDictionary annotDict = annots.getAsDict(i);
PdfName subType = annotDict.getAsName(PdfName.SUBTYPE);
if (subType != null && PdfName.LINK.equals(subType))
{
PdfDictionary action = annotDict.getAsDict(PdfName.A);
if(action != null && PdfName.URI.equals(action.getAsName(PdfName.S)))
{
dests.add(action.getAsString(PdfName.URI).toString());
} // else { its an internal link }
}
}
}
System.out.println(dests);
@ Bobrovsky答案中的示例使用Doxotic搜索鏈接註釋,並使用iText搜索鏈接註釋或PDFBox將被類似地設計您確定文檔中的鏈接確實是鏈接註釋嗎?例如。 Adobe Reader有一個選項,它使內容中的地址可點擊,就好像它們是鏈接註釋,而不是。也許這樣的功能讓你相信有鏈接註釋,而實際上並沒有。 (順便說一句,你可能想提供你嘗試過的代碼;也許這是錯誤的)。 – mkl
非常感謝你已經完成了它。其實我的代碼工作正常,它是Adobe創建懸停鏈接的財產。您能否爲我提供Adobe創建此類媒體資源的規範以便我可以檢查它 –
Adobe Reader只是在頁面內容中搜索它認爲是URL的內容並使它們互動。您可以在首選項中打開或關閉此行爲。我不知道哪些* specs *提供。 – mkl