我有一些包含 URL 和 mailto 形式的超链接的 PDF。现在是否有任何方法或工具(可能是第 3 方)从 PDF 中提取超链接元信息,如坐标、链接类型和目标地址。非常感谢任何帮助。
我已经尝试过使用 iText 和 PDFBox,但没有取得重大成功,甚至一些第三方软件也没有为我提供所需的输出。
我使用 iText 在 Java 中尝试了以下代码
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);