summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-10-03 22:42:00 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-10-12 13:44:14 +0200
commit38abc1f9a91207569b64fc274ccb904094ac4f9a (patch)
tree625aa4aa08d89b490f9a34f8370edce2fca0b055 /apps
parent8be6412105a3c0b9a255b6a89ae164c91d3519de (diff)
downloadmupdf-38abc1f9a91207569b64fc274ccb904094ac4f9a.tar.xz
Add pdfdraw option to print the table of contents / outline.
Diffstat (limited to 'apps')
-rw-r--r--apps/pdfdraw.c71
1 files changed, 65 insertions, 6 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c
index a5f6aa1e..90db4c1b 100644
--- a/apps/pdfdraw.c
+++ b/apps/pdfdraw.c
@@ -19,6 +19,7 @@ int showxml = 0;
int showtext = 0;
int showtime = 0;
int showmd5 = 0;
+int showoutline = 0;
int savealpha = 0;
int uselist = 1;
int alphabits = 8;
@@ -61,6 +62,7 @@ static void usage(void)
"\t-R -\trotate clockwise by given number of degrees\n"
"\t-G gamma\tgamma correct output\n"
"\t-I\tinvert output\n"
+ "\t-l\tprint outline\n"
"\tpages\tcomma separated list of ranges\n");
exit(1);
}
@@ -295,6 +297,56 @@ static void drawrange(pdf_xref *xref, char *range)
}
}
+static int get_page_number(pdf_xref *xref, pdf_link *link)
+{
+ if (link->kind == PDF_LINK_GOTO)
+ return pdf_find_page_number(xref, fz_array_get(link->dest, 0));
+ return 0;
+}
+
+static void print_outline_xml(pdf_xref *xref, pdf_outline *outline, int level)
+{
+ int page;
+ printf("<outline>\n");
+ while (outline)
+ {
+ page = get_page_number(xref, outline->link);
+ printf("<link title=\"%s\" page=\"%d\" />\n",
+ outline->title ? outline->title : "<null>", page);
+ if (outline->child)
+ print_outline_xml(xref, outline->child, level + 1);
+ outline = outline->next;
+ }
+ printf("</outline>\n");
+}
+
+static void print_outline_plain(pdf_xref *xref, pdf_outline *outline, int level)
+{
+ int i, page;
+ while (outline)
+ {
+ page = get_page_number(xref, outline->link);
+ for (i = 0; i < level; i++)
+ putchar('\t');
+ printf("%s %d\n", outline->title ? outline->title : "<null>", page);
+ if (outline->child)
+ print_outline_plain(xref, outline->child, level + 1);
+ outline = outline->next;
+ }
+}
+
+static void drawoutline(pdf_xref *xref)
+{
+ pdf_outline *outline = pdf_load_outline(xref);
+ if (showoutline > 2)
+ pdf_debug_outline(outline, 0);
+ else if (showoutline > 1)
+ print_outline_xml(xref, outline, 0);
+ else
+ print_outline_plain(xref, outline, 0);
+ pdf_free_outline(outline);
+}
+
int main(int argc, char **argv)
{
char *password = "";
@@ -304,7 +356,7 @@ int main(int argc, char **argv)
fz_error error;
int c;
- while ((c = fz_getopt(argc, argv, "o:p:r:R:Aab:dgmtx5G:I")) != -1)
+ while ((c = fz_getopt(argc, argv, "lo:p:r:R:Aab:dgmtx5G:I")) != -1)
{
switch (c)
{
@@ -315,6 +367,7 @@ int main(int argc, char **argv)
case 'A': accelerate = 0; break;
case 'a': savealpha = 1; break;
case 'b': alphabits = atoi(fz_optarg); break;
+ case 'l': showoutline++; break;
case 'm': showtime++; break;
case 't': showtext++; break;
case 'x': showxml++; break;
@@ -332,7 +385,7 @@ int main(int argc, char **argv)
if (fz_optind == argc)
usage();
- if (!showtext && !showxml && !showtime && !showmd5 && !output)
+ if (!showtext && !showxml && !showtime && !showmd5 && !showoutline && !output)
{
printf("nothing to do\n");
exit(0);
@@ -378,10 +431,16 @@ int main(int argc, char **argv)
if (showxml)
printf("<document name=\"%s\">\n", filename);
- if (fz_optind == argc || !isrange(argv[fz_optind]))
- drawrange(xref, "1-");
- if (fz_optind < argc && isrange(argv[fz_optind]))
- drawrange(xref, argv[fz_optind++]);
+ if (showoutline)
+ drawoutline(xref);
+
+ if (showtext || showxml || showtime || showmd5 || output)
+ {
+ if (fz_optind == argc || !isrange(argv[fz_optind]))
+ drawrange(xref, "1-");
+ if (fz_optind < argc && isrange(argv[fz_optind]))
+ drawrange(xref, argv[fz_optind++]);
+ }
if (showxml)
printf("</document>\n");