From daef4e8fb856e84e2a9151cd7715a941a0ae9c6c Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 19 Jun 2022 08:20:43 -0400 Subject: Add more flexible funtions to qpdfjob C API --- include/qpdf/QPDFJob.hh | 2 ++ include/qpdf/qpdfjob-c.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'include') diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 39c7a612..16b1ab74 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -108,6 +108,8 @@ class QPDFJob // and error streams on the caller's behalf. Defaults to "qpdf". QPDF_DLL void setMessagePrefix(std::string const&); + QPDF_DLL + std::string getMessagePrefix() const; // To capture or redirect output, configure the logger returned by // getLogger(). By default, all QPDF and QPDFJob objects share the diff --git a/include/qpdf/qpdfjob-c.h b/include/qpdf/qpdfjob-c.h index b9fe8ccb..e15c8fa5 100644 --- a/include/qpdf/qpdfjob-c.h +++ b/include/qpdf/qpdfjob-c.h @@ -45,6 +45,11 @@ #ifdef __cplusplus extern "C" { #endif + /* SHORT INTERFACE -- These functions are single calls that take + * care of the whole life cycle of QPDFJob. They can be used for + * one-shot ooperations where no additional configuration is + * needed. See FULL INTERFACE below. */ + /* This function does the equivalent of running the qpdf * command-line with the given arguments and returns the exit code * that qpdf would use. argv must be a null-terminated array of @@ -74,6 +79,52 @@ extern "C" { QPDF_DLL int qpdfjob_run_from_json(char const* json); + /* FULL INTERFACE -- new in qpdf11. Similar to the qpdf-c.h API, + * you must call qpdfjob_init to get a qpdfjob_handle and, when + * done, call qpdfjob_cleanup to free resources. Remaining methods + * take qpdfjob_handle as an argument. This interface requires + * more calls but also offers greater flexibility. + */ + typedef struct _qpdfjob_handle* qpdfjob_handle; + QPDF_DLL + qpdfjob_handle qpdfjob_init(); + + QPDF_DLL + void qpdfjob_cleanup(qpdfjob_handle* j); + + /* This function wraps QPDFJob::initializeFromArgv. The return + * value is the same as qpdfjob_run. If this returns an error, it + * is invalid to call any other functions this job handle. + */ + QPDF_DLL + int + qpdfjob_initialize_from_argv(qpdfjob_handle j, char const* const argv[]); + +#ifndef QPDF_NO_WCHAR_T + /* This function is the same as qpdfjob_initialize_from_argv + * except argv is encoded with wide characters. This would be + * suitable for calling from a Windows wmain function. + */ + QPDF_DLL + int qpdfjob_initialize_from_wide_argv( + qpdfjob_handle j, wchar_t const* const argv[]); +#endif /* QPDF_NO_WCHAR_T */ + + /* This function wraps QPDFJob::initializeFromJson. The return + * value is the same as qpdfjob_run. If this returns an error, it + * is invalid to call any other functions this job handle. + */ + QPDF_DLL + int qpdfjob_initialize_from_json(qpdfjob_handle j, char const* json); + + /* This function wraps QPDFJob::run. It returns the error code + * that qpdf would return with the equivalent command-line + * invocation. Exit code values are defined in Constants.h in the + * qpdf_exit_code_e type. + */ + QPDF_DLL + int qpdfjob_run(qpdfjob_handle j); + #ifdef __cplusplus } #endif -- cgit v1.2.3-54-g00ecf