Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top