Java addNamedDestination未将目的地插入新PDF

Java addNamedDestination未将目的地插入新PDF,java,pdf-generation,itext,Java,Pdf Generation,Itext,我正在处理一个PDF文件,可从。操作的一部分是将页面从原始PDF复制到新的PDF,以及复制指定的目的地。iText Java API方法addNamedDestinations没有将目标插入到新PDF中 下面是我的代码段,它基于《iText in Action》(第二版)一书中的示例 try { PdfReader reader1 = new PdfReader("C:\\Temp\\g13-aspef.pdf"); Document doc = new Document();

我正在处理一个PDF文件,可从。操作的一部分是将页面从原始PDF复制到新的PDF,以及复制指定的目的地。iText Java API方法addNamedDestinations没有将目标插入到新PDF中

下面是我的代码段,它基于《iText in Action》(第二版)一书中的示例

try {
    PdfReader reader1 = new PdfReader("C:\\Temp\\g13-aspef.pdf");
    Document doc = new Document();
    PdfCopy copy2 = new PdfCopy(doc, fileout);
    doc.open();
    reader1.consolidateNamedDestinations();
    int n = reader1.getNumberOfPages();
    for (int i = 0; i < n;) {
        copy2.addPage(copy2.getImportedPage(reader1, ++i));

    }
/* myDests indeed includes all 23 destinations appearing in the original PDF. */
    HashMap<String,String> myDests = SimpleNamedDestination.getNamedDestination(reader1, false);
/* Use addNamedDestinations to insert the original destinations into the new PDF. */
    copy2.addNamedDestinations(myDests, 0);
    doc.close();
 } catch (IOException e) {
     System.out.println("Could not copy");
 }
试试看{
PdfReader reader1=新的PdfReader(“C:\\Temp\\g13 aspef.pdf”);
单据单据=新单据();
PdfCopy copy2=新的PdfCopy(文档,文件输出);
doc.open();
reader1.consolidateNamedDestinations();
int n=reader1.getNumberOfPages();
对于(int i=0;i
但是,当我打开创建的PDF时,页面在那里,而不是目的地。为什么我看不到新PDF中的目的地


提前谢谢你

命名目的地不是您可以看到的(没有命名目的地的可视指示),因此请解释您认为命名目的地不存在的原因。在Acrobat Pro(可能还有其他PDF阅读器)中,我们可以查看命名目的地(查看>显示/隐藏>导航窗格>目的地)。例如,关于我上面提到的原始PDF,我看到其中一个目的地是
text_G13.indd:.1752:25
,它在第五页打开。在用上述代码复制的PDF中,导航窗格为空,不显示原始目的地。