From 7cac433e2d9256fb8361aa53d136d4eaacfda6fe Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 5 Jan 2024 16:11:09 -0500 Subject: Implement --set-page-labels and supporting API (fixes #939) --- include/qpdf/Constants.h | 10 ++++++++++ include/qpdf/QPDFJob.hh | 21 +++++++++++++++++++-- include/qpdf/QPDFPageLabelDocumentHelper.hh | 5 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/qpdf/Constants.h b/include/qpdf/Constants.h index 24f7dc3a..89152a91 100644 --- a/include/qpdf/Constants.h +++ b/include/qpdf/Constants.h @@ -232,4 +232,14 @@ enum pdf_annotation_flag_e { /* Encryption/password status for QPDFJob */ enum qpdf_encryption_status_e { qpdf_es_encrypted = 1 << 0, qpdf_es_password_incorrect = 1 << 1 }; +/* Page label types */ +enum qpdf_page_label_e { + pl_none, + pl_digits, + pl_alpha_lower, + pl_alpha_upper, + pl_roman_lower, + pl_roman_upper, +}; + #endif /* QPDFCONSTANTS_H */ diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 9a7afb0f..4626c264 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -296,7 +296,8 @@ class QPDFJob Config* config; }; - class PageLabelsConfig { + class PageLabelsConfig + { friend class QPDFJob; friend class Config; @@ -458,6 +459,22 @@ class QPDFJob std::vector repeat_pagenos; }; + struct PageLabelSpec + { + PageLabelSpec( + int first_page, qpdf_page_label_e label_type, int start_num, std::string_view prefix) : + first_page(first_page), + label_type(label_type), + start_num(start_num), + prefix(prefix) + { + } + int first_page; + qpdf_page_label_e label_type; + int start_num{1}; + std::string prefix; + }; + // Helper functions static void usage(std::string const& msg); static JSON json_schema(int json_version, std::set* keys = nullptr); @@ -694,7 +711,7 @@ class QPDFJob bool json_output{false}; std::string update_from_json; bool report_mem_usage{false}; - std::vector page_label_specs; + std::vector page_label_specs; }; std::shared_ptr m; }; diff --git a/include/qpdf/QPDFPageLabelDocumentHelper.hh b/include/qpdf/QPDFPageLabelDocumentHelper.hh index eb610544..57b6919c 100644 --- a/include/qpdf/QPDFPageLabelDocumentHelper.hh +++ b/include/qpdf/QPDFPageLabelDocumentHelper.hh @@ -49,6 +49,11 @@ class QPDFPageLabelDocumentHelper: public QPDFDocumentHelper QPDF_DLL bool hasPageLabels(); + // Helper function to create a dictionary suitable for adding to the /PageLabels numbers tree. + QPDF_DLL + static QPDFObjectHandle + pageLabelDict(qpdf_page_label_e label_type, int start_num, std::string_view prefix); + // Return a page label dictionary representing the page label for the given page. The page does // not need to appear explicitly in the page label dictionary. This method will adjust /St as // needed to produce a label that is suitable for the page. -- cgit v1.2.3-54-g00ecf