我正在操作https://www.census.gov/content/dam/Census/library/publications/2015/econ/g13-aspef.pdf中提供的PDF . 操作的一部分是将页面从原始PDF复制到新PDF,还复制命名目标 . iText Java API方法addNamedDestinations未将目标插入新PDF .

下面是我的代码段,它基于iText in Action,第2版中的示例 .

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");
 }

但是,当我打开创建的PDF时,页面就在那里,但不是目的地 . 为什么我在新PDF中看不到目的地?

先感谢您!