I am working on populating the pdf’s bookmark and displaying it into a Tree View.
This is the bookmark:
I have converted those bookmarks into xml, I am using a third party dll i.e. itextsharp in it and now just have to display it into tree view.
Here is the xml format:
My designer code or the xaml code:
<Window.Resources>
<HierarchicalDataTemplate
x:Key="NodeTemplate"
ItemsSource="{Binding
XPath=./*}">
<TextBlock x:Name="nodetext"/>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding
Path=NodeType}"
Value="Element">
<Setter TargetName="nodetext"
Property="Text"
Value="{Binding
Path=Name}" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"
/>
</Grid.RowDefinitions>
<TreeView Name="trvItems">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding}">
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding
Title}">
<TextBlock Text="{Binding
Text}"/>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
<TextBlock Text="{Binding
Text}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
My xaml.cs code:
string filename = System.AppDomain.CurrentDomain.BaseDirectory;
filename =@"E:\test.pdf";
string outputbookmark =@"E:\Tree Grid\Tree Grid\bin\Debug\HA.xml";
var Sbytes =File.ReadAllBytes(filename);
PdfReader pdfReader =newPdfReader(Sbytes);
IList<Dictionary<string,object>> bookmarks =SimpleBookmark.GetBookmark(pdfReader);
using (StreamWriter
Sw = newStreamWriter(outputbookmark))
{
SimpleBookmark.ExportToXML(bookmarks, Sw,"ISO8859-1",true);
}
var bookmark =XmlParser<Bookmark>.Deserialize(outputbookmark);
trvItems.DataContext = bookmark;
I am getting all the bookmarks here now what to do to display it into tree view properly.