문제

I'm trying to merge PDF's, while transferring nameddestinations to new merged file, its shifted to page destination instead of named, please verify the code below.

For i As Integer = 0 To bookOrder.SelectNodes("//fileInfo/filename").Count - 1
        reader = New PdfReader(bookOrder.SelectNodes("//fileInfo/filename").Item(i).InnerText)
        reader.ConsolidateNamedDestinations()
        n = reader.NumberOfPages
        tempBookmarks = SimpleBookmark.GetBookmark(reader)

        If i = 0 Then
            document = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
            pdfCpy = New PdfCopy(document, New FileStream(outputPdf, FileMode.Create))
            document.Open()
            SimpleBookmark.ShiftPageNumbers(tempBookmarks, page_offset, Nothing)
            page_offset += n
            If tempBookmarks IsNot Nothing Then
                bookmarks.AddRange(tempBookmarks)
            End If

            totalPages = n

        Else

            SimpleBookmark.ShiftPageNumbers(tempBookmarks, page_offset, Nothing)
            If tempBookmarks IsNot Nothing Then
                bookmarks.AddRange(tempBookmarks)
            End If

            page_offset += n
            totalPages += n
        End If

        For j As Integer = 1 To n
            page = pdfCpy.GetImportedPage(reader, j)
            pdfCpy.AddPage(page)
        Next

        pdfCpy.AddNamedDestinations(SimpleNamedDestination.GetNamedDestination(reader, False), page_offset - n)


        reader.Close()
    Next

Its working fine, but link destination changed from named to page... Please let me know where i need to correct to sort out this issue.

도움이 되었습니까?

해결책

You instruct iText to consolidate named destinations using ConsolidateNamedDestinations(). This function replaces all the local named links with the actual destinations. If you remove this method from your code, named destinations will not be altered.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top