2014-10-12 79 views
0

我使用HTML從EVO PDF轉換器來創建一個PDF文檔,我用下面的代碼來生成書籤用於h標籤:嵌套書籤PDF

// Create a HTML to PDF converter object with default settings 
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(); 

// Select the HTML elements to bookmark by setting a list of CSS selectors 
htmlToPdfConverter.PdfBookmarkOptions.HtmlElementSelectors = new string[] { "H1", "H2", "H3" }; 

// Display the bookmarks panel in PDF viewer when the generated PDF is opened 
htmlToPdfConverter.PdfViewerPreferences.PageMode = ViewerPageMode.UseOutlines; 

// Convert the HTML page to a PDF document in a memory buffer 
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(urlTextBox.Text); 

的書籤出現在觀衆,但他們都在同一級別。我希望將它們組織在一棵樹上,第一層爲H1標籤,第二層爲H2標籤,等等。我發現了另一個可以按照我想要的方式組織書籤的軟件,但是我想避免僅僅爲此使用其他工具。我想直接在樹中生成書籤。

+0

(檢查API參考後)[AddBookmark](http://www.evopdf.com/api/html/M_EvoPdf_Document_AddBookmark_1.htm)是否這樣做,用「h2」作爲其最後的「h1」父母? – usr2564301 2014-10-12 11:35:22

回答

1

有兩種方法可以在生成的PDF文檔中自動創建書籤。一種是通過API,並且是您已經使用的方法,但不會產生您想要的書籤層次結構。

另一種方法是設置以下行代碼:

// Enable the creation of a hierarchy of bookmarks from H1 to H6 tags 
htmlToPdfConverter.PdfBookmarkOptions.AutoBookmarksEnabled = true; 

這將使基於在HTML的標題標記書籤的樹的創建。

+0

謝謝。這解決了這個問題。 – 2014-10-13 11:54:33