-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
51 lines (41 loc) · 1.46 KB
/
Copy pathMain.cs
File metadata and controls
51 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace PDFBookmarkReader
{
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using iTextSharp.text.pdf;
class MainClass
{
private static Regex _whitespaceRegex = new Regex(@"\s{2,}", RegexOptions.Compiled);
public static void Main (string[] args)
{
if (args.Length < 1)
{
Console.WriteLine ("Usage: pdfBookmarkReader.exe pdffile.pdf");
return;
}
string file = args[0];
if (! System.IO.File.Exists (file))
{
Console.WriteLine ("File {0} is missing", file);
return;
}
PdfReader pr = new PdfReader(file);
IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pr);
Console.WriteLine ("<PDF>\n\t<PageCount>{0}</PageCount>\n\t<Bookmarks Total=\"{1}\">\t", pr.NumberOfPages, bookmarks.Count);
if (bookmarks != null)
{
foreach (Dictionary<string, object> bookmark in bookmarks)
{
string title = (string)bookmark["Title"];
title = _whitespaceRegex.Replace(title, " ");
string[] pageData = ((string)(bookmark["Page"])).Split(' ');
string page = pageData[0];
page = page.Trim();
Console.WriteLine ("\t\t<Bookmark>\n\t\t\t<Title>{0}</Title>\n\t\t\t<Page>{1}</Page>\n\t\t</Bookmark>", title, page);
}
}
Console.WriteLine("\t</Bookmarks>\n</PDF>");
}
}
}