在PDF文件中重命名命名目标 [英] Renaming named destinations in PDF files

查看:409
本文介绍了在PDF文件中重命名命名目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在PDF文件中使用命名目的地来打开文件中特定位置的PDF文件。负责生成PDF文档的团队使用工具从书签自动生成命名目的地,因此命名目的地往往具有* 9_Glossary *或* Additional_Information *等名称。我们被要求用多种语言制作相同的文件。我希望我们将提供多种外语的PDF文档,书签位于相同的位置,但书签的名称当然是这些其他语言,自动生成的命名目的地将使用外语。我希望所有文件中的命名目的地都一样。

I've been using named destinations in PDF files to open the PDF file at a specific location in the file. The team responsible for generating the PDF document uses a tool to automatically generated named destinations from book marks, so the named destinations tend to have names like *9_Glossary* or *Additional_Information*. We've been asked to produce the same documents in multiple languages. I expect the we will be supplied PDF documents in multiple foreign languages with bookmarks in the same locations, but the names of the book marks will of course be in these other languages, and the automatically generated named destinations will be in the foreign language. I would like the named destinations in all the documents to be the same.

我不能成为第一个遇到这个问题的人,所以我很感兴趣看看是否其他人已经处理过这个问题。

I can't be the first person to run into this problem, so I'm interested to see if others have dealt with this.

可能的一个想法可能是重命名外语文件中的目的地。我使用iSharpText来提取命名目的地列表。 iSharpText可以重命名目的地吗?理想情况下,我有一个工具,我的翻译可以使用它来匹配每种语言中的命名目的地名称,然后让工具替换命名的目的地名称。

One thought that comes to might might be to rename the destinations in the foreign language documents. I have used iSharpText to extract a list of named destinations. Is it possible to iSharpText to rename the destination? Ideally, I'd have a tool that my translator could use to match the named destination names in each language, then have the tool replace the named destination names.

另一个想法是维护一个实时执行翻译的数据库;翻译器仍然必须匹配命名的目标名称,但它们存储在数据库中。命令Adobe Reader打开的程序将使用英文版本查找外语名称,然后使用它来打开文档。

Another thought is to maintain a database where the translation is performed in real time; the translator still has to match of named destination names, but they are stored in a database. The program that orders Adobe Reader to open would use the English version to look up the foreign language name and then use that to open the document.

我也有兴趣在PDF创作工具的建议中可能会使这个问题更容易解决。

I'd also be interested in recommendations of PDF authoring tools that might make this problem easier to solve.

推荐答案

请看一下 RenameDestinations 。它的功能超出了您的需求,因为原始文档本身包含指向目标的链接,并且为了继续工作,我们需要更改引用我们已更改的名称的操作。

Please take a look at the example RenameDestinations. It's doing more than you need, because the original document itself contains links to the named destinations and for those to keep working, we need to change the action that refers to the names we've changed.

这是与您相关的部分:

PdfDictionary catalog = reader.getCatalog();
PdfDictionary names = catalog.getAsDict(PdfName.NAMES);
PdfDictionary dests = names.getAsDict(PdfName.DESTS);
PdfArray name = dests.getAsArray(PdfName.NAMES);
for (int i = 0; i < name.size(); i += 2) {
    PdfString original = name.getAsString(i);
    PdfString newName = new PdfString("new" + original.toString());
    name.set(i, newName);
}

首先获得根词典(或目录)。你得到 / Names 字典,寻找命名目的地( / Dests )。在我的例子中,我有一个简单的数组,其中包含 PdfString 对,以及对 PdfArray 值的引用。我用新名称替换所有字符串值。

First you get the root dictionary (or catalog). You get the /Names dictionary, looking for named destinations (/Dests). In my case, I have a simple array with pairs of PdfString and references to PdfArray values. I replace all the string values with new names.

我正在改变的结构是名称树,它通常不是线性的。在您的PDF中,此树可以具有分支,因此您可能希望编写递归方法来遍历这些分支。我没有时间写一个更详细的例子,也不想为你偷工作。这个例子可以帮助你。

The structure I'm changing like this, is a name tree, and it usually isn't that linear. In your PDF, this tree can have branches, so you may want to write a recursive method to go through those branches. I don't have the time to write a more elaborate example, nor do I want to steal your job for you. This example should help you on your way.

请注意,我在 Map 命名重命名。我使用此地图更改第一页上链接注释的目的地。

Note that I keep track of the original and new names in a Map named renamed. I use this map to change the destinations of the Link annotations on the first page.

这篇关于在PDF文件中重命名命名目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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