Intro
Some PDF documents can contain the TOC
(table of contents) to simplify navigation within the PDF file and to
allow structured content representation. It's the thing you usually
see then you click on Bookmarks tab
in Acrobat Reader. So this table of contents is usually being created
by using bookmark objects (this is the PDF name for such objects as
defined in specification). This object supports navigation as well as
link (see our older posts: working
with build-in navigation and how
to work with links in PDF documents) being a bit different.
While
the samples listed above provide code and theory for highlighting
search results or link targets on PDF page, current sample is
designed to show the bookmark basics for the most common task –
enumerate bookmarks list and show doc's table of contents.
The code
C#
code sample below demonstrates how it could be done using our API.
///
<summary>
///
Demonstrates bookmarks enumeration in PDF file.
///
</summary>
class
Program
{
static
void
Main(string[]
args)
{
//
open and load the file
using
(FileStream
fs = new
FileStream(@"..\..\..\Documents\development
guide.pdf", FileMode.Open))
{
//
this object represents a PDF document
using(Document
document = new
Document(fs))
{
EnumerateBookmarksAndPrint(document.Bookmarks);
}
}
Console.ReadLine();
}
///
<summary>
///
Enumerates the bookmarks and prints their title.
///
</summary>
///
<param
name="bookmark">The
bookmark.</param>
private
static
void
EnumerateBookmarksAndPrint(Bookmark
bookmark)
{
if(bookmark!=null)
{
Console.WriteLine(bookmark.Title);
for(int
i=0;i<bookmark.Children.Count;i++)
{
EnumerateBookmarksAndPrint(bookmark.Children[i]);
}
}
}
}
Output
1.
Introduction
2.
Getting started
2.1
Development environment
2.2
Deployment & installation
2.3
Licensing process
2.3.1
Using custom assembly attribute
2.3.2
Applying license manually
3.
Product description
3.1
PDF versions supported
3.2.
Features and limitations
3.3.
Output formats
3.4
Processing highlights
4.
Code samples
4.1.
Convert PDF document to Bitmap
4.2.
Convert PDF to TIFF
4.3.
Viewing information about PDF document
4.4.
Extracting font information from PDF files
4.5
Advanced conversion using rendering settings
The
sample can be found in our download
package and is located in Samples\BookmarksUsage folder.
It's
also possible to highlight bookmark's destinaton and save desired PDF
page to image using the API provided by Apitron PDF Rasterizer for
.NET.
No comments:
Post a Comment