1

我从 itextsharp 开始,我已经设法回答了我所有的问题,但一个:如何设置书签以打开 fitpage 缩放/视图?

如果这已经在其他地方得到回答,我深表歉意。如果有帮助,这是我的代码。

//编辑:下面是我的工作代码。它已使用 Bruno 的示例进行了修改。

 Public Sub MergePDFFiles(FileList As System.Collections.Generic.List(Of ModifiedItemForList), pdfName As String, pageCount As Integer)

    Dim reader As PdfReader
    Dim mergedPdf As Byte() = Nothing
    Dim n As Integer
    Dim page As Integer
    Dim par As Paragraph
    Dim pageMode As Integer
    Dim pageLayout As Integer
    Dim pageZoom As PdfDestination
    Dim outlineZoom As PdfDestination
    Dim pdfAction As PdfAction
    Dim root As PdfOutline
    Dim pdfOutline As PdfOutline

    Using ms As New MemoryStream()

        Using document As New Document()

            Using copy As New PdfCopy(document, ms)
                'Dim copy As New PdfCopy(document, ms)
                document.Open()
                root = copy.RootOutline
                pageMode = copy.PageModeUseOutlines
                pageLayout = copy.PageLayoutSinglePage
                pageZoom = New PdfDestination(PdfDestination.FIT)
                copy.ViewerPreferences = pageMode
                pdfAction = pdfAction.GotoLocalPage(1, pageZoom, copy)
                copy.SetOpenAction(pdfAction)

                ' For Each FilePath As KeyValuePair(Of String, String) In FileList  ' .Count - 1
                For i As Integer = 0 To pageCount - 1
                    ' FilePath As KeyValuePair(Of String, String)
                    If File.Exists(FileList.Item(i).Value) Then
                        reader = New PdfReader(FileList.Item(i).Value)
                        ' loop over the pages in that document
                        n = reader.NumberOfPages
                        page = 0
                        par = New Paragraph(FileList.Item(i).Key)
                        Debug.Print("FileList.Item(i).Key = " & FileList.Item(i).Key)
                        outlineZoom = New PdfDestination(PdfDestination.FIT)
                        pdfOutline = New PdfOutline(root, outlineZoom, par)

                        While page < n
                            copy.AddPage(copy.GetImportedPage(reader, System.Threading.Interlocked.Increment(page)))
                        End While

                    End If

                Next

            End Using

        End Using

        mergedPdf = ms.ToArray()

    End Using

    File.WriteAllBytes(pdfName, mergedPdf)

End Sub

您的意见将不胜感激,Corbin de Bruin

4

1 回答 1

0

如果您想要自定义书签,请不要使用Chapterand SectionPdfOutline而是使用。这(当然)记录在我的书的第 7 章中。如果您需要示例的 C# 端口,请查看第 7 章的代码示例,特别是CreateOutlineTree.cs,其中不使用(for Fit Horizo​​ntally) 和 Y 位置,您只需使用(并且没有额外的范围):PdfDestination.FITHPdfDestination.FIT

new PdfOutline(root, new PdfDestination(PdfDestination.FIT), title, true);
于 2013-05-14T21:22:15.170 回答