2009-09-27 03:11:29 +00:00
|
|
|
#include <qpdf/qpdf-c.h>
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
#include <qpdf/QPDF.hh>
|
|
|
|
#include <qpdf/QPDFWriter.hh>
|
|
|
|
#include <qpdf/QTC.hh>
|
2009-10-20 00:24:44 +00:00
|
|
|
#include <qpdf/QPDFExc.hh>
|
2018-02-17 16:51:10 +00:00
|
|
|
#include <qpdf/Pl_Discard.hh>
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2020-11-29 00:48:07 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2009-09-27 14:39:04 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
2011-08-11 14:48:37 +00:00
|
|
|
#include <cstring>
|
2021-12-02 13:57:05 +00:00
|
|
|
#include <functional>
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
struct _qpdf_error
|
|
|
|
{
|
|
|
|
PointerHolder<QPDFExc> exc;
|
|
|
|
};
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
struct _qpdf_data
|
2009-09-27 03:11:29 +00:00
|
|
|
{
|
2009-09-27 14:39:04 +00:00
|
|
|
_qpdf_data();
|
|
|
|
~_qpdf_data();
|
|
|
|
|
2019-06-22 18:24:49 +00:00
|
|
|
PointerHolder<QPDF> qpdf;
|
|
|
|
PointerHolder<QPDFWriter> qpdf_writer;
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
PointerHolder<QPDFExc> error;
|
|
|
|
_qpdf_error tmp_error;
|
|
|
|
std::list<QPDFExc> warnings;
|
2009-09-27 14:39:04 +00:00
|
|
|
std::string tmp_string;
|
2009-10-20 00:24:44 +00:00
|
|
|
|
|
|
|
// Parameters for functions we call
|
2010-10-04 15:24:10 +00:00
|
|
|
char const* filename; // or description
|
|
|
|
char const* buffer;
|
2012-06-24 19:26:28 +00:00
|
|
|
unsigned long long size;
|
2009-10-20 00:24:44 +00:00
|
|
|
char const* password;
|
2011-08-11 15:56:37 +00:00
|
|
|
bool write_memory;
|
2019-06-22 18:24:49 +00:00
|
|
|
PointerHolder<Buffer> output_buffer;
|
2020-11-29 00:48:07 +00:00
|
|
|
|
|
|
|
// QPDFObjectHandle support
|
2021-12-10 16:09:42 +00:00
|
|
|
void (*oh_error_handler)(qpdf_data, qpdf_error, void*);
|
|
|
|
void* oh_error_handler_data;
|
|
|
|
bool default_oh_error_handler_called;
|
2020-11-29 00:48:07 +00:00
|
|
|
std::map<qpdf_oh, PointerHolder<QPDFObjectHandle>> oh_cache;
|
|
|
|
qpdf_oh next_oh;
|
|
|
|
std::set<std::string> cur_iter_dict_keys;
|
|
|
|
std::set<std::string>::const_iterator dict_iter;
|
|
|
|
std::string cur_dict_key;
|
2009-09-27 03:11:29 +00:00
|
|
|
};
|
|
|
|
|
2021-12-10 16:09:42 +00:00
|
|
|
static void default_oh_error_handler(qpdf_data qpdf, qpdf_error e, void* data)
|
|
|
|
{
|
|
|
|
bool* called = reinterpret_cast<bool*>(data);
|
|
|
|
if (called != nullptr)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c warn about oh error", *called ? 0 : 1);
|
|
|
|
if (! *called)
|
|
|
|
{
|
|
|
|
qpdf->warnings.push_back(
|
|
|
|
QPDFExc(
|
|
|
|
qpdf_e_internal,
|
|
|
|
qpdf->qpdf->getFilename(),
|
|
|
|
"", 0,
|
|
|
|
"C API object handle accessor errors occurred,"
|
|
|
|
" and the application did not define an error handler"));
|
|
|
|
*called = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << e->exc->what() << std::endl;
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
_qpdf_data::_qpdf_data() :
|
2020-11-29 00:48:07 +00:00
|
|
|
write_memory(false),
|
2021-12-10 16:09:42 +00:00
|
|
|
oh_error_handler(default_oh_error_handler),
|
|
|
|
oh_error_handler_data(&this->default_oh_error_handler_called),
|
|
|
|
default_oh_error_handler_called(false),
|
2020-11-29 00:48:07 +00:00
|
|
|
next_oh(0)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
_qpdf_data::~_qpdf_data()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-20 19:43:08 +00:00
|
|
|
class ProgressReporter: public QPDFWriter::ProgressReporter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProgressReporter(void (*handler)(int, void*), void* data);
|
|
|
|
virtual ~ProgressReporter() = default;
|
|
|
|
virtual void reportProgress(int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void (*handler)(int, void*);
|
|
|
|
void* data;
|
|
|
|
};
|
|
|
|
|
|
|
|
ProgressReporter::ProgressReporter(void (*handler)(int, void*), void* data) :
|
|
|
|
handler(handler),
|
|
|
|
data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProgressReporter::reportProgress(int progress)
|
|
|
|
{
|
|
|
|
this->handler(progress, this->data);
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:46:26 +00:00
|
|
|
// must set qpdf->filename and qpdf->password
|
|
|
|
static void call_read(qpdf_data qpdf)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2009-10-20 00:46:26 +00:00
|
|
|
qpdf->qpdf->processFile(qpdf->filename, qpdf->password);
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 15:24:10 +00:00
|
|
|
// must set qpdf->filename, qpdf->buffer, qpdf->size, and qpdf->password
|
|
|
|
static void call_read_memory(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
qpdf->qpdf->processMemoryFile(qpdf->filename, qpdf->buffer,
|
2019-06-21 03:35:23 +00:00
|
|
|
QIntC::to_size(qpdf->size), qpdf->password);
|
2010-10-04 15:24:10 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 00:46:26 +00:00
|
|
|
// must set qpdf->filename
|
2009-10-20 01:35:46 +00:00
|
|
|
static void call_init_write(qpdf_data qpdf)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2009-10-20 00:46:26 +00:00
|
|
|
qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf), qpdf->filename);
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 15:56:37 +00:00
|
|
|
static void call_init_write_memory(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf));
|
|
|
|
qpdf->qpdf_writer->setOutputMemory();
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:46:26 +00:00
|
|
|
static void call_write(qpdf_data qpdf)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2009-10-20 00:46:26 +00:00
|
|
|
qpdf->qpdf_writer->write();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 16:51:10 +00:00
|
|
|
static void call_check(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QPDFWriter w(*qpdf->qpdf);
|
|
|
|
Pl_Discard discard;
|
|
|
|
w.setOutputPipeline(&discard);
|
|
|
|
w.setDecodeLevel(qpdf_dl_all);
|
|
|
|
w.write();
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:57:05 +00:00
|
|
|
static QPDF_ERROR_CODE trap_errors(
|
|
|
|
qpdf_data qpdf, std::function<void(qpdf_data)> fn)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
try
|
|
|
|
{
|
2009-10-20 00:46:26 +00:00
|
|
|
fn(qpdf);
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
catch (QPDFExc& e)
|
|
|
|
{
|
|
|
|
qpdf->error = new QPDFExc(e);
|
|
|
|
status |= QPDF_ERRORS;
|
|
|
|
}
|
|
|
|
catch (std::runtime_error& e)
|
|
|
|
{
|
|
|
|
qpdf->error = new QPDFExc(qpdf_e_system, "", "", 0, e.what());
|
2009-10-20 00:59:38 +00:00
|
|
|
status |= QPDF_ERRORS;
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
qpdf->error = new QPDFExc(qpdf_e_internal, "", "", 0, e.what());
|
2009-10-20 00:59:38 +00:00
|
|
|
status |= QPDF_ERRORS;
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qpdf_more_warnings(qpdf))
|
|
|
|
{
|
|
|
|
status |= QPDF_WARNINGS;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-10-24 13:23:20 +00:00
|
|
|
char const* qpdf_get_qpdf_version()
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version");
|
|
|
|
return QPDF::QPDFVersion().c_str();
|
|
|
|
}
|
|
|
|
|
2009-09-27 03:11:29 +00:00
|
|
|
qpdf_data qpdf_init()
|
|
|
|
{
|
2009-09-27 14:39:04 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init");
|
|
|
|
qpdf_data qpdf = new _qpdf_data();
|
|
|
|
qpdf->qpdf = new QPDF();
|
|
|
|
return qpdf;
|
2009-09-27 03:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_cleanup(qpdf_data* qpdf)
|
|
|
|
{
|
2009-09-27 14:39:04 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_cleanup");
|
2020-11-29 00:48:07 +00:00
|
|
|
qpdf_oh_release_all(*qpdf);
|
2021-12-10 16:09:42 +00:00
|
|
|
if ((*qpdf)->error.getPointer())
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c cleanup warned about unhandled error");
|
|
|
|
std::cerr << "WARNING: application did not handle error: "
|
|
|
|
<< (*qpdf)->error->what() << std::endl;
|
|
|
|
|
|
|
|
}
|
2009-09-27 03:11:29 +00:00
|
|
|
delete *qpdf;
|
|
|
|
*qpdf = 0;
|
|
|
|
}
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2021-12-02 12:54:33 +00:00
|
|
|
size_t qpdf_get_last_string_length(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
return qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_more_warnings");
|
|
|
|
|
|
|
|
if (qpdf->warnings.empty())
|
|
|
|
{
|
2009-10-20 00:24:44 +00:00
|
|
|
std::vector<QPDFExc> w = qpdf->qpdf->getWarnings();
|
2009-09-27 14:39:04 +00:00
|
|
|
if (! w.empty())
|
|
|
|
{
|
|
|
|
qpdf->warnings.assign(w.begin(), w.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (qpdf->warnings.empty())
|
|
|
|
{
|
|
|
|
return QPDF_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QPDF_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-23 15:27:30 +00:00
|
|
|
QPDF_BOOL qpdf_has_error(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_has_error");
|
|
|
|
return (qpdf->error.getPointer() ? QPDF_TRUE : QPDF_FALSE);
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf_error qpdf_get_error(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2009-10-20 00:24:44 +00:00
|
|
|
if (qpdf->error.getPointer())
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf->tmp_error.exc = qpdf->error;
|
|
|
|
qpdf->error = 0;
|
2009-10-23 15:27:30 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");
|
2009-10-20 00:24:44 +00:00
|
|
|
return &qpdf->tmp_error;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf_error qpdf_next_warning(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
if (qpdf_more_warnings(qpdf))
|
|
|
|
{
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf->tmp_error.exc = new QPDFExc(qpdf->warnings.front());
|
2009-09-27 14:39:04 +00:00
|
|
|
qpdf->warnings.pop_front();
|
2009-09-27 16:01:45 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");
|
2009-10-20 00:24:44 +00:00
|
|
|
return &qpdf->tmp_error;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
|
|
|
|
{
|
2009-10-23 16:50:22 +00:00
|
|
|
if (e == 0)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->what();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
|
|
|
|
{
|
2009-10-23 16:50:22 +00:00
|
|
|
if (e == 0)
|
|
|
|
{
|
|
|
|
return qpdf_e_success;
|
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getErrorCode();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
|
|
|
|
{
|
2009-10-23 16:50:22 +00:00
|
|
|
if (e == 0)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getFilename().c_str();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-24 19:26:28 +00:00
|
|
|
unsigned long long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2009-10-23 16:50:22 +00:00
|
|
|
if (e == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-06-21 03:35:23 +00:00
|
|
|
return QIntC::to_ulonglong(e->exc->getFilePosition());
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
|
|
|
|
{
|
2009-10-23 16:50:22 +00:00
|
|
|
if (e == 0)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getMessageDetail().c_str();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 16:51:10 +00:00
|
|
|
QPDF_ERROR_CODE qpdf_check_pdf(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = trap_errors(qpdf, &call_check);
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_check_pdf");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
void qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_suppress_warnings");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf->setSuppressWarnings(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_ignore_xref_streams(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_ignore_xref_streams");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf->setIgnoreXRefStreams(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_attempt_recovery(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_attempt_recovery");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf->setAttemptRecovery(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE qpdf_read(qpdf_data qpdf, char const* filename,
|
|
|
|
char const* password)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf->filename = filename;
|
|
|
|
qpdf->password = password;
|
2009-10-20 00:46:26 +00:00
|
|
|
status = trap_errors(qpdf, &call_read);
|
2017-07-26 18:38:49 +00:00
|
|
|
// We no longer have a good way to exercise a file with both
|
|
|
|
// warnings and errors because qpdf is getting much better at
|
|
|
|
// recovering.
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_read",
|
|
|
|
(status == 0) ? 0
|
|
|
|
: (status & QPDF_WARNINGS) ? 1
|
|
|
|
: (status & QPDF_ERRORS) ? 2 :
|
|
|
|
-1
|
|
|
|
);
|
2009-09-27 14:39:04 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2010-10-04 15:24:10 +00:00
|
|
|
QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf,
|
|
|
|
char const* description,
|
|
|
|
char const* buffer,
|
2012-06-24 19:26:28 +00:00
|
|
|
unsigned long long size,
|
2010-10-04 15:24:10 +00:00
|
|
|
char const* password)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
qpdf->filename = description;
|
|
|
|
qpdf->buffer = buffer;
|
|
|
|
qpdf->size = size;
|
|
|
|
qpdf->password = password;
|
|
|
|
status = trap_errors(qpdf, &call_read_memory);
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_read_memory", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
char const* qpdf_get_pdf_version(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_pdf_version");
|
|
|
|
qpdf->tmp_string = qpdf->qpdf->getPDFVersion();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
|
2012-12-31 11:47:11 +00:00
|
|
|
int qpdf_get_pdf_extension_level(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_pdf_extension_level");
|
|
|
|
return qpdf->qpdf->getExtensionLevel();
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
char const* qpdf_get_user_password(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_user_password");
|
|
|
|
qpdf->tmp_string = qpdf->qpdf->getTrimmedUserPassword();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
|
2011-08-11 14:48:37 +00:00
|
|
|
char const* qpdf_get_info_key(qpdf_data qpdf, char const* key)
|
|
|
|
{
|
|
|
|
char const* result = 0;
|
|
|
|
QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
|
|
|
|
if (trailer.hasKey("/Info"))
|
|
|
|
{
|
|
|
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
|
|
|
if (info.hasKey(key))
|
|
|
|
{
|
|
|
|
QPDFObjectHandle value = info.getKey(key);
|
|
|
|
if (value.isString())
|
|
|
|
{
|
|
|
|
qpdf->tmp_string = value.getStringValue();
|
|
|
|
result = qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTC::TC("qpdf", "qpdf-c get_info_key", (result == 0 ? 0 : 1));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value)
|
|
|
|
{
|
|
|
|
if ((key == 0) || (std::strlen(key) == 0) || (key[0] != '/'))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPDFObjectHandle value_object;
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c set_info_key to value");
|
|
|
|
value_object = QPDFObjectHandle::newString(value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c set_info_key to null");
|
|
|
|
value_object = QPDFObjectHandle::newNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
|
|
|
|
if (! trailer.hasKey("/Info"))
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c add info to trailer");
|
|
|
|
trailer.replaceKey(
|
|
|
|
"/Info",
|
2012-06-22 14:09:42 +00:00
|
|
|
qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c set-info-key use existing info");
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
|
|
|
info.replaceOrRemoveKey(key, value_object);
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
QPDF_BOOL qpdf_is_linearized(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_is_linearized");
|
|
|
|
return (qpdf->qpdf->isLinearized() ? QPDF_TRUE : QPDF_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_is_encrypted(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_is_encrypted");
|
|
|
|
return (qpdf->qpdf->isEncrypted() ? QPDF_TRUE : QPDF_FALSE);
|
|
|
|
}
|
|
|
|
|
2009-09-27 20:05:38 +00:00
|
|
|
QPDF_BOOL qpdf_allow_accessibility(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_accessibility");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowAccessibility() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_extract_all(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_extract_all");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowExtractAll() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_print_low_res(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_print_low_res");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowPrintLowRes() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_print_high_res(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_print_high_res");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowPrintHighRes() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_assembly(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_assembly");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowModifyAssembly() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_form(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_form");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowModifyForm() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_annotation(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_annotation");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowModifyAnnotation() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_other(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_other");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowModifyOther() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_all(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_all");
|
2019-06-21 10:32:09 +00:00
|
|
|
return (qpdf->qpdf->allowModifyAll() ? QPDF_TRUE : QPDF_FALSE);
|
2009-09-27 20:05:38 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 15:56:37 +00:00
|
|
|
static void qpdf_init_write_internal(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2019-06-22 18:24:49 +00:00
|
|
|
if (qpdf->qpdf_writer.getPointer())
|
2009-10-20 00:46:26 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");
|
|
|
|
qpdf->qpdf_writer = 0;
|
2019-06-22 18:24:49 +00:00
|
|
|
if (qpdf->output_buffer.getPointer())
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
qpdf->output_buffer = 0;
|
|
|
|
qpdf->write_memory = false;
|
|
|
|
qpdf->filename = 0;
|
|
|
|
}
|
2009-10-20 00:46:26 +00:00
|
|
|
}
|
2011-08-11 15:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE qpdf_init_write(qpdf_data qpdf, char const* filename)
|
|
|
|
{
|
|
|
|
qpdf_init_write_internal(qpdf);
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf->filename = filename;
|
2011-08-11 15:56:37 +00:00
|
|
|
QPDF_ERROR_CODE status = trap_errors(qpdf, &call_init_write);
|
2009-09-27 14:39:04 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init_write", status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2011-08-11 15:56:37 +00:00
|
|
|
QPDF_ERROR_CODE qpdf_init_write_memory(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
qpdf_init_write_internal(qpdf);
|
|
|
|
QPDF_ERROR_CODE status = trap_errors(qpdf, &call_init_write_memory);
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init_write_memory");
|
|
|
|
qpdf->write_memory = true;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qpdf_get_buffer_internal(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
if (qpdf->write_memory && (qpdf->output_buffer == 0))
|
|
|
|
{
|
|
|
|
qpdf->output_buffer = qpdf->qpdf_writer->getBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t qpdf_get_buffer_length(qpdf_data qpdf)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
qpdf_get_buffer_internal(qpdf);
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t result = 0;
|
2019-06-22 18:24:49 +00:00
|
|
|
if (qpdf->output_buffer.getPointer())
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
result = qpdf->output_buffer->getSize();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char const* qpdf_get_buffer(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
unsigned char const* result = 0;
|
|
|
|
qpdf_get_buffer_internal(qpdf);
|
2019-06-22 18:24:49 +00:00
|
|
|
if (qpdf->output_buffer.getPointer())
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
result = qpdf->output_buffer->getBuffer();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-10-19 20:17:14 +00:00
|
|
|
void qpdf_set_object_stream_mode(qpdf_data qpdf, qpdf_object_stream_e mode)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_object_stream_mode");
|
2009-10-19 20:17:14 +00:00
|
|
|
qpdf->qpdf_writer->setObjectStreamMode(mode);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 00:11:10 +00:00
|
|
|
void qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_compress_streams");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setCompressStreams(value != QPDF_FALSE);
|
2017-09-12 00:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_decode_level(qpdf_data qpdf, qpdf_stream_decode_level_e level)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_decode_level");
|
|
|
|
qpdf->qpdf_writer->setDecodeLevel(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_preserve_unreferenced_objects");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setPreserveUnreferencedObjects(value != QPDF_FALSE);
|
2017-09-12 00:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_newline_before_endstream");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setNewlineBeforeEndstream(value != QPDF_FALSE);
|
2017-09-12 00:11:10 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 20:17:14 +00:00
|
|
|
void qpdf_set_stream_data_mode(qpdf_data qpdf, qpdf_stream_data_e mode)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_stream_data_mode");
|
2009-10-19 20:17:14 +00:00
|
|
|
qpdf->qpdf_writer->setStreamDataMode(mode);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_content_normalization(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_content_normalization");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setContentNormalization(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_qdf_mode(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_qdf_mode");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setQDFMode(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-25 15:09:25 +00:00
|
|
|
void qpdf_set_deterministic_ID(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_deterministic_ID");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setDeterministicID(value != QPDF_FALSE);
|
2015-10-25 15:09:25 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
void qpdf_set_static_ID(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_static_ID");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setStaticID(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 00:36:51 +00:00
|
|
|
void qpdf_set_static_aes_IV(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_static_aes_IV");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setStaticAesIV(value != QPDF_FALSE);
|
2009-10-19 00:36:51 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
void qpdf_set_suppress_original_object_IDs(
|
|
|
|
qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_suppress_original_object_IDs");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setSuppressOriginalObjectIDs(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_preserve_encryption");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setPreserveEncryption(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_r2_encryption_parameters(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_print, QPDF_BOOL allow_modify,
|
|
|
|
QPDF_BOOL allow_extract, QPDF_BOOL allow_annotate)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r2_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR2EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_print != QPDF_FALSE, allow_modify != QPDF_FALSE,
|
|
|
|
allow_extract != QPDF_FALSE, allow_annotate != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 01:45:08 +00:00
|
|
|
void qpdf_set_r3_encryption_parameters2(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
|
|
|
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
|
|
|
enum qpdf_r3_print_e print)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR3EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
|
|
|
allow_assemble != QPDF_FALSE, allow_annotate_and_form != QPDF_FALSE,
|
|
|
|
allow_form_filling != QPDF_FALSE, allow_modify_other != QPDF_FALSE,
|
2019-01-15 01:45:08 +00:00
|
|
|
print);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_r4_encryption_parameters2(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
|
|
|
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
|
|
|
enum qpdf_r3_print_e print,
|
|
|
|
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR4EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
|
|
|
allow_assemble != QPDF_FALSE, allow_annotate_and_form != QPDF_FALSE,
|
|
|
|
allow_form_filling != QPDF_FALSE, allow_modify_other != QPDF_FALSE,
|
|
|
|
print, encrypt_metadata != QPDF_FALSE, use_aes != QPDF_FALSE);
|
2019-01-15 01:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void qpdf_set_r5_encryption_parameters2(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
|
|
|
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
|
|
|
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR5EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
|
|
|
allow_assemble != QPDF_FALSE, allow_annotate_and_form != QPDF_FALSE,
|
|
|
|
allow_form_filling != QPDF_FALSE, allow_modify_other != QPDF_FALSE,
|
|
|
|
print, encrypt_metadata != QPDF_FALSE);
|
2019-01-15 01:45:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_r6_encryption_parameters2(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
|
|
|
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
|
|
|
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR6EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
|
|
|
allow_assemble != QPDF_FALSE, allow_annotate_and_form != QPDF_FALSE,
|
|
|
|
allow_form_filling != QPDF_FALSE, allow_modify_other != QPDF_FALSE,
|
|
|
|
print, encrypt_metadata != QPDF_FALSE);
|
2019-01-15 01:45:08 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
void qpdf_set_r3_encryption_parameters(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
2009-10-19 20:17:14 +00:00
|
|
|
qpdf_r3_print_e print, qpdf_r3_modify_e modify)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2021-11-10 22:57:12 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#endif
|
2009-09-27 14:39:04 +00:00
|
|
|
qpdf->qpdf_writer->setR3EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
2019-06-21 10:32:09 +00:00
|
|
|
print, modify);
|
2021-11-10 22:57:12 +00:00
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 00:36:51 +00:00
|
|
|
void qpdf_set_r4_encryption_parameters(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
2009-10-19 20:17:14 +00:00
|
|
|
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
|
|
|
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
|
2009-10-19 00:36:51 +00:00
|
|
|
{
|
2021-11-10 22:57:12 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#endif
|
2009-10-19 00:36:51 +00:00
|
|
|
qpdf->qpdf_writer->setR4EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
2019-06-21 10:32:09 +00:00
|
|
|
print, modify,
|
2020-04-03 18:27:15 +00:00
|
|
|
encrypt_metadata != QPDF_FALSE, use_aes != QPDF_FALSE);
|
2021-11-10 22:57:12 +00:00
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
2009-10-19 00:36:51 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 11:47:11 +00:00
|
|
|
void qpdf_set_r5_encryption_parameters(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
|
|
|
QPDF_BOOL encrypt_metadata)
|
|
|
|
{
|
2021-11-10 22:57:12 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#endif
|
2012-12-31 11:47:11 +00:00
|
|
|
qpdf->qpdf_writer->setR5EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
2019-06-21 10:32:09 +00:00
|
|
|
print, modify,
|
2020-04-03 18:27:15 +00:00
|
|
|
encrypt_metadata != QPDF_FALSE);
|
2021-11-10 22:57:12 +00:00
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
2012-12-31 11:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_r6_encryption_parameters(
|
|
|
|
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
|
|
|
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
|
|
|
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
|
|
|
QPDF_BOOL encrypt_metadata)
|
|
|
|
{
|
2021-11-10 22:57:12 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#endif
|
2012-12-31 11:47:11 +00:00
|
|
|
qpdf->qpdf_writer->setR6EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2020-04-03 18:27:15 +00:00
|
|
|
allow_accessibility != QPDF_FALSE, allow_extract != QPDF_FALSE,
|
|
|
|
print, modify, encrypt_metadata != QPDF_FALSE);
|
2021-11-10 22:57:12 +00:00
|
|
|
#if (defined(__GNUC__) || defined(__clang__))
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
#endif
|
2012-12-31 11:47:11 +00:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
void qpdf_set_linearization(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_linearization");
|
2020-04-03 18:27:15 +00:00
|
|
|
qpdf->qpdf_writer->setLinearization(value != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 00:42:48 +00:00
|
|
|
void qpdf_set_minimum_pdf_version(qpdf_data qpdf, char const* version)
|
2012-12-31 11:47:11 +00:00
|
|
|
{
|
|
|
|
qpdf_set_minimum_pdf_version_and_extension(qpdf, version, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_minimum_pdf_version_and_extension(
|
|
|
|
qpdf_data qpdf, char const* version, int extension_level)
|
2009-10-05 00:42:48 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_minimum_pdf_version");
|
2012-12-31 11:47:11 +00:00
|
|
|
qpdf->qpdf_writer->setMinimumPDFVersion(version, extension_level);
|
2009-10-05 00:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_force_pdf_version(qpdf_data qpdf, char const* version)
|
2012-12-31 11:47:11 +00:00
|
|
|
{
|
|
|
|
qpdf_force_pdf_version_and_extension(qpdf, version, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_force_pdf_version_and_extension(
|
|
|
|
qpdf_data qpdf, char const* version, int extension_level)
|
2009-10-05 00:42:48 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_force_pdf_version");
|
2012-12-31 11:47:11 +00:00
|
|
|
qpdf->qpdf_writer->forcePDFVersion(version, extension_level);
|
2009-10-05 00:42:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 19:43:08 +00:00
|
|
|
void qpdf_register_progress_reporter(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
void (*report_progress)(int percent, void* data),
|
|
|
|
void* data)
|
|
|
|
{
|
2021-12-09 23:34:22 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c registered progress reporter");
|
2020-12-20 19:43:08 +00:00
|
|
|
qpdf->qpdf_writer->registerProgressReporter(
|
|
|
|
new ProgressReporter(report_progress, data));
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
QPDF_ERROR_CODE qpdf_write(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
2009-10-20 00:46:26 +00:00
|
|
|
status = trap_errors(qpdf, &call_write);
|
2017-07-27 22:18:18 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_write", (status == 0) ? 0 : 1);
|
2009-09-27 14:39:04 +00:00
|
|
|
return status;
|
|
|
|
}
|
2020-11-29 00:48:07 +00:00
|
|
|
|
2021-12-10 16:09:42 +00:00
|
|
|
void qpdf_register_oh_error_handler(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
void (*handle_error)(qpdf_data qpdf, qpdf_error error, void* data),
|
|
|
|
void* data)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c registered oh error handler");
|
|
|
|
qpdf->oh_error_handler = handle_error;
|
|
|
|
qpdf->oh_error_handler_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class RET>
|
|
|
|
static RET trap_oh_errors(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
std::function<RET()> fallback,
|
|
|
|
std::function<RET(qpdf_data)> fn)
|
|
|
|
{
|
|
|
|
// Note: fallback is a function so we don't have to evaluate it
|
|
|
|
// unless needed. This is important because sometimes the fallback
|
|
|
|
// creates an object.
|
|
|
|
RET ret;
|
|
|
|
QPDF_ERROR_CODE status = trap_errors(qpdf, [&ret, &fn] (qpdf_data q) {
|
|
|
|
ret = fn(q);
|
|
|
|
});
|
|
|
|
if (status & QPDF_ERRORS)
|
|
|
|
{
|
|
|
|
(*qpdf->oh_error_handler)(
|
|
|
|
qpdf, qpdf_get_error(qpdf), qpdf->oh_error_handler_data);
|
|
|
|
return fallback();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:48:07 +00:00
|
|
|
static qpdf_oh
|
|
|
|
new_object(qpdf_data qpdf, QPDFObjectHandle const& qoh)
|
|
|
|
{
|
|
|
|
qpdf_oh oh = ++qpdf->next_oh; // never return 0
|
|
|
|
qpdf->oh_cache[oh] = new QPDFObjectHandle(qoh);
|
|
|
|
return oh;
|
|
|
|
}
|
|
|
|
|
2021-12-02 16:47:04 +00:00
|
|
|
qpdf_oh qpdf_oh_new_object(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_new_object");
|
|
|
|
return new_object(qpdf, *(qpdf->oh_cache[oh]));
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:48:07 +00:00
|
|
|
void qpdf_oh_release(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_release");
|
|
|
|
qpdf->oh_cache.erase(oh);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_release_all(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_release_all");
|
|
|
|
qpdf->oh_cache.clear();
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:09:42 +00:00
|
|
|
template <class T>
|
|
|
|
static std::function<T()> return_T(T const& r)
|
|
|
|
{
|
|
|
|
return [&r]() { return r; };
|
|
|
|
}
|
|
|
|
|
|
|
|
static QPDF_BOOL return_false()
|
|
|
|
{
|
|
|
|
return QPDF_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::function<qpdf_oh()> return_uninitialized(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
return [qpdf]() { return qpdf_oh_new_uninitialized(qpdf); };
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::function<qpdf_oh()> return_null(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
return [qpdf]() { return qpdf_oh_new_null(qpdf); };
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:48:07 +00:00
|
|
|
qpdf_oh qpdf_get_trailer(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_trailer");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
|
|
|
qpdf, return_uninitialized(qpdf), [] (qpdf_data q) {
|
|
|
|
return new_object(q, q->qpdf->getTrailer());
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_get_root(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_root");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
|
|
|
qpdf, return_uninitialized(qpdf), [] (qpdf_data q) {
|
|
|
|
return new_object(q, q->qpdf->getRoot());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-10 19:57:11 +00:00
|
|
|
qpdf_oh qpdf_get_object_by_id(qpdf_data qpdf, int objid, int generation)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_object_by_id");
|
|
|
|
return new_object(qpdf, qpdf->qpdf->getObjectByID(objid, generation));
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:09:42 +00:00
|
|
|
template<class RET>
|
|
|
|
static RET do_with_oh(
|
|
|
|
qpdf_data qpdf, qpdf_oh oh,
|
|
|
|
std::function<RET()> fallback,
|
|
|
|
std::function<RET(QPDFObjectHandle&)> fn)
|
|
|
|
{
|
|
|
|
return trap_oh_errors<RET>(
|
|
|
|
qpdf, fallback, [&fn, &oh](qpdf_data q) {
|
|
|
|
auto i = q->oh_cache.find(oh);
|
|
|
|
bool result = ((i != q->oh_cache.end()) &&
|
|
|
|
(i->second).getPointer());
|
|
|
|
if (! result)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c invalid object handle");
|
|
|
|
throw QPDFExc(
|
|
|
|
qpdf_e_internal,
|
|
|
|
q->qpdf->getFilename(),
|
|
|
|
std::string("C API object handle ") +
|
|
|
|
QUtil::uint_to_string(oh),
|
|
|
|
0, "attempted access to unknown object handle");
|
|
|
|
}
|
|
|
|
return fn(*(q->oh_cache[oh]));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_with_oh_void(
|
|
|
|
qpdf_data qpdf, qpdf_oh oh,
|
|
|
|
std::function<void(QPDFObjectHandle&)> fn)
|
|
|
|
{
|
|
|
|
do_with_oh<bool>(
|
|
|
|
qpdf, oh, return_T<bool>(false), [&fn](QPDFObjectHandle& o) {
|
|
|
|
fn(o);
|
|
|
|
return true; // unused
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 19:57:11 +00:00
|
|
|
void qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &objid, &generation](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_replace_object");
|
|
|
|
qpdf->qpdf->replaceObject(objid, generation, o);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:04:59 +00:00
|
|
|
QPDF_BOOL qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isInitialized();
|
|
|
|
});
|
2021-12-02 13:04:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 00:48:07 +00:00
|
|
|
QPDF_BOOL qpdf_oh_is_bool(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_bool");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isBool();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_null(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_null");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isNull();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_integer(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_integer");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isInteger();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_real(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_real");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isReal();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_name(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isName();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_string(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_string");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isString();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_operator(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_operator");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isOperator();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_inline_image(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_inline_image");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isInlineImage();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_array(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_array");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isArray();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_dictionary(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isDictionary();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_stream(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_stream");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isStream();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_indirect(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_indirect");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isIndirect();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_scalar");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
return o.isScalar();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_number(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_number");
|
|
|
|
return o.isNumber();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_wrap_in_array(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
|
|
|
qpdf, oh,
|
|
|
|
[&qpdf](){ return qpdf_oh_new_array(qpdf); },
|
|
|
|
[&qpdf](QPDFObjectHandle& qoh) {
|
|
|
|
if (qoh.isArray())
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c array to wrap_in_array");
|
|
|
|
return new_object(qpdf, qoh);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c non-array to wrap_in_array");
|
|
|
|
return new_object(qpdf,
|
|
|
|
QPDFObjectHandle::newArray(
|
|
|
|
std::vector<QPDFObjectHandle>{qoh}));
|
|
|
|
}
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_parse(qpdf_data qpdf, char const* object_str)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_parse");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
|
|
|
qpdf, return_uninitialized(qpdf), [&object_str] (qpdf_data q) {
|
|
|
|
return new_object(q, QPDFObjectHandle::parse(object_str));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_bool_value");
|
|
|
|
return o.getBoolValue();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long long qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<long long>(
|
|
|
|
qpdf, oh, return_T<long long>(0LL), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value");
|
|
|
|
return o.getIntValue();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<int>(
|
|
|
|
qpdf, oh, return_T<int>(0), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_int_value_as_int");
|
|
|
|
return o.getIntValueAsInt();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<unsigned long long>(
|
|
|
|
qpdf, oh, return_T<unsigned long long>(0ULL), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value");
|
|
|
|
return o.getUIntValue();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<unsigned int>(
|
|
|
|
qpdf, oh, return_T<unsigned int>(0U), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_uint_value_as_uint");
|
|
|
|
return o.getUIntValueAsUInt();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_real_value");
|
|
|
|
qpdf->tmp_string = o.getRealValue();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<double>(
|
|
|
|
qpdf, oh, return_T<double>(0.0), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_numeric_value");
|
|
|
|
return o.getNumericValue();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_name");
|
|
|
|
qpdf->tmp_string = o.getName();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_string_value");
|
|
|
|
qpdf->tmp_string = o.getStringValue();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_utf8_value");
|
|
|
|
qpdf->tmp_string = o.getUTF8Value();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<int>(
|
|
|
|
qpdf, oh, return_T<int>(0), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_n_items");
|
|
|
|
return o.getArrayNItems();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
|
|
|
qpdf, oh, return_null(qpdf), [&qpdf, &n](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_array_item");
|
|
|
|
return new_object(qpdf, o.getArrayItem(n));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_begin_dict_key_iter(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
qpdf->cur_iter_dict_keys = do_with_oh<std::set<std::string>>(
|
|
|
|
qpdf, oh,
|
|
|
|
[](){ return std::set<std::string>(); },
|
|
|
|
[](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_begin_dict_key_iter");
|
|
|
|
return o.getKeys();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
qpdf->dict_iter = qpdf->cur_iter_dict_keys.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_dict_more_keys(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_dict_more_keys");
|
|
|
|
return qpdf->dict_iter != qpdf->cur_iter_dict_keys.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_dict_next_key(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_dict_next_key");
|
|
|
|
if (qpdf_oh_dict_more_keys(qpdf))
|
|
|
|
{
|
|
|
|
qpdf->cur_dict_key = *qpdf->dict_iter;
|
|
|
|
++qpdf->dict_iter;
|
|
|
|
return qpdf->cur_dict_key.c_str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [&key](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key");
|
|
|
|
return o.hasKey(key);
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
|
|
|
qpdf, oh, return_null(qpdf), [&qpdf, &key](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_key");
|
|
|
|
return new_object(qpdf, o.getKey(key));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [&key](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name");
|
|
|
|
return o.isOrHasName(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_uninitialized(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_uninitialized");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle());
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_null(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_null");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_bool(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_bool");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newBool(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_integer(qpdf_data qpdf, long long value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_integer");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newInteger(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_real_from_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newReal(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_real_from_double(qpdf_data qpdf,
|
|
|
|
double value, int decimal_places)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_real_from_double");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newReal(value, decimal_places));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_name(qpdf_data qpdf, char const* name)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_name");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newName(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_string(qpdf_data qpdf, char const* str)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newString(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_unicode_string(qpdf_data qpdf, char const* utf8_str)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_unicode_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newUnicodeString(utf8_str));
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_array(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_array");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_new_dictionary(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_dictionary");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newDictionary());
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_make_direct");
|
|
|
|
o.makeDirect();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 19:57:11 +00:00
|
|
|
qpdf_oh qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
|
|
|
return do_with_oh<qpdf_oh>(
|
|
|
|
qpdf, oh,
|
|
|
|
return_uninitialized(qpdf),
|
|
|
|
[&qpdf](QPDFObjectHandle& o) {
|
|
|
|
return new_object(qpdf, qpdf->qpdf->makeIndirectObject(o));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:48:07 +00:00
|
|
|
static QPDFObjectHandle
|
|
|
|
qpdf_oh_item_internal(qpdf_data qpdf, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDFObjectHandle>(
|
|
|
|
qpdf, item,
|
|
|
|
[](){return QPDFObjectHandle::newNull();},
|
|
|
|
[](QPDFObjectHandle& o) {
|
|
|
|
return o;
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh,
|
|
|
|
int at, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &at, &item](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_set_array_item");
|
|
|
|
o.setArrayItem(at, qpdf_oh_item_internal(qpdf, item));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &at, &item](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_insert_item");
|
|
|
|
o.insertItem(at, qpdf_oh_item_internal(qpdf, item));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_append_item(qpdf_data qpdf, qpdf_oh oh, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &item](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_append_item");
|
|
|
|
o.appendItem(qpdf_oh_item_internal(qpdf, item));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&at](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_erase_item");
|
|
|
|
o.eraseItem(at);
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_replace_key(qpdf_data qpdf, qpdf_oh oh,
|
|
|
|
char const* key, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &key, &item](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_key");
|
|
|
|
o.replaceKey(key, qpdf_oh_item_internal(qpdf, item));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&key](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_remove_key");
|
|
|
|
o.removeKey(key);
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_oh_replace_or_remove_key(qpdf_data qpdf, qpdf_oh oh,
|
|
|
|
char const* key, qpdf_oh item)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
do_with_oh_void(
|
|
|
|
qpdf, oh, [&qpdf, &key, &item](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key");
|
|
|
|
o.replaceOrRemoveKey(key, qpdf_oh_item_internal(qpdf, item));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qpdf_oh qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
|
|
|
qpdf, oh, return_null(qpdf), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict");
|
|
|
|
return new_object(qpdf, o.getDict());
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qpdf_oh_get_object_id(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<int>(
|
|
|
|
qpdf, oh, return_T<int>(0), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_object_id");
|
|
|
|
return o.getObjectID();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qpdf_oh_get_generation(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<int>(
|
|
|
|
qpdf, oh, return_T<int>(0), [](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_generation");
|
|
|
|
return o.getGeneration();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_unparse(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_unparse");
|
|
|
|
qpdf->tmp_string = o.unparse();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_unparse_resolved(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_unparse_resolved");
|
|
|
|
qpdf->tmp_string = o.unparseResolved();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh)
|
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
|
|
|
qpdf, oh, return_T<char const*>(""), [&qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_unparse_binary");
|
|
|
|
qpdf->tmp_string = o.unparseBinary();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|