mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +00:00
QPDFJob: convert pages
This commit is contained in:
parent
9373881cca
commit
41c5af8f26
@ -32,17 +32,6 @@ def write_file(filename):
|
||||
os.rename(tmpfile, filename)
|
||||
|
||||
|
||||
# QXXXQ
|
||||
# These need manual handlers.
|
||||
complex = set([
|
||||
'add-attachment',
|
||||
'copy-attachments-from',
|
||||
'encrypt',
|
||||
'overlay',
|
||||
'pages',
|
||||
'underlay',
|
||||
])
|
||||
|
||||
# QXXXQ
|
||||
# These are trivial but not in main and so need a different config
|
||||
# object. Some are in more than one table.
|
||||
@ -466,8 +455,8 @@ class Main:
|
||||
for i, [kind, v] in flags.items():
|
||||
self.options_without_help.add(f'--{i}')
|
||||
add_jdata(i, table_prefix or table)
|
||||
# QXXXQ complex, not_yet
|
||||
if i in complex or i in not_yet or config is None:
|
||||
# QXXXQ not_yet
|
||||
if i in not_yet or config is None or i in o.get('manual', []):
|
||||
identifier = self.to_identifier(i, arg_prefix, False)
|
||||
self.handle_flag(i, identifier, kind, v)
|
||||
else:
|
||||
@ -581,7 +570,7 @@ class Main:
|
||||
['choices', 'options', 'no-json', 'json']))
|
||||
for o in data['options']:
|
||||
self.check_keys('top', o, set(
|
||||
['table', 'prefix', 'config', 'bare', 'positional',
|
||||
['table', 'prefix', 'config', 'manual', 'bare', 'positional',
|
||||
'optional_parameter', 'required_parameter',
|
||||
'required_choices', 'optional_choices', 'from_table']))
|
||||
|
||||
|
@ -135,6 +135,17 @@ class QPDFJob
|
||||
bool replace;
|
||||
};
|
||||
|
||||
struct PageSpec
|
||||
{
|
||||
PageSpec(std::string const& filename,
|
||||
char const* password,
|
||||
std::string const& range);
|
||||
|
||||
std::string filename;
|
||||
std::shared_ptr<char> password;
|
||||
std::string range;
|
||||
};
|
||||
|
||||
public:
|
||||
class Config;
|
||||
|
||||
@ -172,6 +183,24 @@ class QPDFJob
|
||||
CopyAttachmentFrom caf;
|
||||
};
|
||||
|
||||
class PagesConfig
|
||||
{
|
||||
friend class QPDFJob;
|
||||
friend class Config;
|
||||
public:
|
||||
PagesConfig& pageSpec(std::string const& filename,
|
||||
char const* password,
|
||||
std::string const& range);
|
||||
|
||||
# include <qpdf/auto_job_c_pages.hh>
|
||||
|
||||
private:
|
||||
PagesConfig(Config&);
|
||||
PagesConfig(PagesConfig const&) = delete;
|
||||
|
||||
Config& config;
|
||||
};
|
||||
|
||||
// Configuration is performed by calling methods XXX QXXXQ document
|
||||
class Config
|
||||
{
|
||||
@ -180,6 +209,7 @@ class QPDFJob
|
||||
QPDF_DLL
|
||||
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
|
||||
std::shared_ptr<AttConfig> addAttachment();
|
||||
std::shared_ptr<PagesConfig> pages();
|
||||
|
||||
# include <qpdf/auto_job_c_main.hh>
|
||||
|
||||
@ -243,17 +273,6 @@ class QPDFJob
|
||||
static void parse_object_id(
|
||||
std::string const& objspec, bool& trailer, int& obj, int& gen);
|
||||
|
||||
struct PageSpec
|
||||
{
|
||||
PageSpec(std::string const& filename,
|
||||
char const* password,
|
||||
std::string const& range);
|
||||
|
||||
std::string filename;
|
||||
std::shared_ptr<char> password;
|
||||
std::string range;
|
||||
};
|
||||
|
||||
struct RotationSpec
|
||||
{
|
||||
RotationSpec(int angle = 0, bool relative = false) :
|
||||
|
6
include/qpdf/auto_job_c_pages.hh
Normal file
6
include/qpdf/auto_job_c_pages.hh
Normal file
@ -0,0 +1,6 @@
|
||||
//
|
||||
// This file is automatically generated by generate_auto_job.
|
||||
// Edits will be automatically overwritten if the build is
|
||||
// run in maintainer mode.
|
||||
//
|
||||
QPDF_DLL Config& end();
|
5
job.sums
5
job.sums
@ -1,9 +1,10 @@
|
||||
# Generated by generate_auto_job
|
||||
generate_auto_job d9f75a50dd4e503ede676bad54f80f856de096da7f3ad0e4594b0d09a6e1215d
|
||||
generate_auto_job 66e43cdb4ae166d020be19fcc6f8e9f0445c4de6a5395ff5aff511b89763c4e1
|
||||
include/qpdf/auto_job_c_att.hh ecc3f8f711b486b491e811176362a90c022eb225ff12157df3a10ca021be87b1
|
||||
include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
|
||||
include/qpdf/auto_job_c_main.hh 5fdd9c85aa295a3caec467b9607fe82c874cd3aaeb7806b9d18074f7b96fd085
|
||||
job.yml e649f7dbb3748584f338b330043336ce4a4d51a34b00b42caa89dcfbc7bdcb84
|
||||
include/qpdf/auto_job_c_pages.hh 79ee6e52a36fedfd0e6ca60bd926bc25a3e975ab6fa984a7e798a48791e8ba86
|
||||
job.yml 4cd60df0caa74b68cc39352910a8381c3411248bc3edef69f9d16d75e807f451
|
||||
libqpdf/qpdf/auto_job_decl.hh 38f7462e34fea7d46d5e5519ac1742be6e57ea6f66c47b37d5425f3a2b9ca536
|
||||
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
||||
libqpdf/qpdf/auto_job_init.hh b49d839078d84398142f8f14bdae8a71f44fbff13cdf7b350b84ef2410aaa6a3
|
||||
|
10
job.yml
10
job.yml
@ -61,6 +61,13 @@ options:
|
||||
- job-json-help
|
||||
- table: main
|
||||
config: c_main
|
||||
manual:
|
||||
- add-attachment
|
||||
- copy-attachments-from
|
||||
- encrypt
|
||||
- overlay
|
||||
- pages
|
||||
- underlay
|
||||
positional: true
|
||||
bare:
|
||||
- add-attachment
|
||||
@ -148,8 +155,11 @@ options:
|
||||
remove-unreferenced-resources: remove_unref
|
||||
stream-data: stream_data
|
||||
- table: pages
|
||||
config: c_pages
|
||||
prefix: Pages
|
||||
positional: true
|
||||
manual:
|
||||
- password
|
||||
required_parameter:
|
||||
password: password
|
||||
- table: encryption
|
||||
|
@ -46,6 +46,7 @@ namespace
|
||||
std::shared_ptr<QPDFJob::Config> c_main;
|
||||
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
|
||||
std::shared_ptr<QPDFJob::AttConfig> c_att;
|
||||
std::shared_ptr<QPDFJob::PagesConfig> c_pages;
|
||||
std::vector<char*> accumulated_args; // points to member in ap
|
||||
char* pages_password;
|
||||
};
|
||||
@ -310,6 +311,7 @@ ArgParser::argPages()
|
||||
usage("the --pages may only be specified one time");
|
||||
}
|
||||
this->accumulated_args.clear();
|
||||
this->c_pages = c_main->pages();
|
||||
this->ap.selectOptionTable(O_PAGES);
|
||||
}
|
||||
|
||||
@ -402,7 +404,7 @@ ArgParser::argPagesPositional(char* arg)
|
||||
{
|
||||
range = "1-z";
|
||||
}
|
||||
o.page_specs.push_back(QPDFJob::PageSpec(file, this->pages_password, range));
|
||||
this->c_pages->pageSpec(file, this->pages_password, range);
|
||||
this->accumulated_args.clear();
|
||||
this->pages_password = nullptr;
|
||||
if (next_file != nullptr)
|
||||
@ -415,10 +417,8 @@ void
|
||||
ArgParser::argEndPages()
|
||||
{
|
||||
argPagesPositional(nullptr);
|
||||
if (o.page_specs.empty())
|
||||
{
|
||||
usage("--pages: no page specifications given");
|
||||
}
|
||||
c_pages->end();
|
||||
c_pages = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -657,3 +657,34 @@ QPDFJob::AttConfig::end()
|
||||
this->config.o.attachments_to_add.push_back(this->att);
|
||||
return this->config;
|
||||
}
|
||||
|
||||
QPDFJob::PagesConfig::PagesConfig(Config& c) :
|
||||
config(c)
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<QPDFJob::PagesConfig>
|
||||
QPDFJob::Config::pages()
|
||||
{
|
||||
return std::shared_ptr<PagesConfig>(new PagesConfig(*this));
|
||||
}
|
||||
|
||||
QPDFJob::Config&
|
||||
QPDFJob::PagesConfig::end()
|
||||
{
|
||||
if (this->config.o.page_specs.empty())
|
||||
{
|
||||
throw QPDFJob::ConfigError("--pages: no page specifications given");
|
||||
}
|
||||
return this->config;
|
||||
}
|
||||
|
||||
QPDFJob::PagesConfig&
|
||||
QPDFJob::PagesConfig::pageSpec(std::string const& filename,
|
||||
char const* password,
|
||||
std::string const& range)
|
||||
{
|
||||
this->config.o.page_specs.push_back(
|
||||
QPDFJob::PageSpec(filename, password, range));
|
||||
return *this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user