diff options
-rw-r--r-- | include/mupdf/pdf/page.h | 8 | ||||
-rw-r--r-- | source/pdf/pdf-page.c | 18 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h index 7cf6da44..1b8fa755 100644 --- a/include/mupdf/pdf/page.h +++ b/include/mupdf/pdf/page.h @@ -6,6 +6,14 @@ int pdf_count_pages(fz_context *ctx, pdf_document *doc); pdf_obj *pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle); /* + pdf_lookup_anchor: Find the page number of a named destination. + + For use with looking up the destination page of a fragment + identifier in hyperlinks: foo.pdf#bar. +*/ +int pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name); + +/* pdf_load_page: Load a page and its resources. Locates the page in the PDF document and loads the page and its diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index dcb0add4..d893d204 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -200,6 +200,24 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node) return total; } +int +pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name) +{ + pdf_obj *needle, *dest; + fz_link_dest ld; + + needle = pdf_new_string(ctx, doc, name, strlen(name)); + fz_try(ctx) + dest = pdf_lookup_dest(ctx, doc, needle); + fz_always(ctx) + pdf_drop_obj(ctx, needle); + fz_catch(ctx) + fz_rethrow(ctx); + + ld = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTO, dest); + return ld.ld.gotor.page; +} + static pdf_obj * pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node, pdf_obj *key) { |