2013-05-14 319 views
1

我開始與itextsharp,我已經設法回答我的所有問題,但只有一個: 書籤如何設置爲打開fitpage縮放/視圖?itextsharp設置書籤,以適應頁面

如果此問題已在其他地方得到解答,我表示歉意。 這是我的代碼,如果它有幫助。

//編輯:下面是我的工作代碼。它已經使用布魯諾的例子進行了修改。

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 

您的輸入將不勝感激, 科爾賓日布魯因

回答

0

如果你想自定義書籤,請不要使用ChapterSection,使用PdfOutline代替。這(當然)記錄在我的bookchapter 7中。如果您需要示例的C#端口,請查看code examples for chapter 7,特別是CreateOutlineTree.cs,而不是使用PdfDestination.FITH(用於Fit Horizo​​ntally)和Y位置,您只需創建一個帶有PdfDestination.FIT(且不需要額外參數)的目標:

new PdfOutline(root, new PdfDestination(PdfDestination.FIT), title, true); 
+0

謝謝你的幫助布魯諾。我在上面發佈了修改代碼以適應您的示例和建議。 – 2013-05-15 18:04:12