aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2024-01-05 22:11:09 +0100
committerJay Berkenbilt <ejb@ql.org>2024-01-05 23:12:12 +0100
commit7cac433e2d9256fb8361aa53d136d4eaacfda6fe (patch)
tree91e18e06655d5d83dd745032641cdd7406785ced /include
parent543038c52a3e0dc166565142ed7efb183e461948 (diff)
downloadqpdf-7cac433e2d9256fb8361aa53d136d4eaacfda6fe.tar.zst
Implement --set-page-labels and supporting API (fixes #939)
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/Constants.h10
-rw-r--r--include/qpdf/QPDFJob.hh21
-rw-r--r--include/qpdf/QPDFPageLabelDocumentHelper.hh5
3 files changed, 34 insertions, 2 deletions
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<int> 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<std::string>* keys = nullptr);
@@ -694,7 +711,7 @@ class QPDFJob
bool json_output{false};
std::string update_from_json;
bool report_mem_usage{false};
- std::vector<std::string> page_label_specs;
+ std::vector<PageLabelSpec> page_label_specs;
};
std::shared_ptr<Members> 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.