如何使用pdfbox向一组pdf文件添加相对超链接? [英] How do I add relative hyperlinks to a group of pdf files using pdfbox?

查看:882
本文介绍了如何使用pdfbox向一组pdf文件添加相对超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实现解析一组pdf以检索每个pdfs元数据的功能。然后通过在每个pdf中引用另一个pdf的地方添加超链接链接来链接这些。我能够创建绝对超链接。但是将这些pdf上传到服务器后,可以将它们从服务器下载到任何本地机器路径。我希望这些超链接在下载到不同的位置后工作。那么,如何创建相对于pdfs组的超链接?

I am currently implementing functionality to parse a group of pdf's to retrieve each pdfs meta data.And then interlink these by adding hyperlinks links to each pdf wherever another pdf is being referenced inside it.I am able to create absolute hyperlinks.But after these pdfs are uploaded to a server, then they can be downloaded from server to any local machine path.I want these hyperlinks to work after they are downloaded to a different location.So, how can create hyperlinks which are relative the group of pdfs?

推荐答案

以下是解决我问题的代码:

Here is the code which solved my issue :

PDActionRemoteGoTo remoteGoto = new PDActionRemoteGoTo();
PDComplexFileSpecification fileDesc = new PDComplexFileSpecification();
fileDesc.setFile(System.IO.Path.GetFileName(filePath));
                            remoteGoto.setOpenInNewWindow(true);
                            remoteGoto.setFile(fileDesc);
                            txtLink.setAction(remoteGoto);
 txtLink.setRectangle(rect);
 page.getAnnotations().add(txtLink);

这篇关于如何使用pdfbox向一组pdf文件添加相对超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆