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>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2022-09-08 19:57:33 +00:00
|
|
|
#include <qpdf/BufferInputSource.hh>
|
2021-12-17 18:28:11 +00:00
|
|
|
#include <qpdf/Pl_Buffer.hh>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/Pl_Discard.hh>
|
2022-09-08 19:57:33 +00:00
|
|
|
#include <qpdf/Pl_Function.hh>
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/QPDFExc.hh>
|
2022-06-18 14:33:27 +00:00
|
|
|
#include <qpdf/QPDFLogger.hh>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/QPDFWriter.hh>
|
|
|
|
#include <qpdf/QTC.hh>
|
2020-11-29 00:48:07 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2022-09-09 12:03:21 +00:00
|
|
|
#include <qpdf/qpdflogger-c_impl.hh>
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2011-08-11 14:48:37 +00:00
|
|
|
#include <cstring>
|
2021-12-02 13:57:05 +00:00
|
|
|
#include <functional>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <list>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2009-10-20 00:24:44 +00:00
|
|
|
struct _qpdf_error
|
|
|
|
{
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<QPDFExc> exc;
|
2009-10-20 00:24:44 +00:00
|
|
|
};
|
|
|
|
|
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();
|
2022-04-15 23:44:07 +00:00
|
|
|
~_qpdf_data() = default;
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<QPDF> qpdf;
|
|
|
|
std::shared_ptr<QPDFWriter> qpdf_writer;
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<QPDFExc> error;
|
2009-10-20 00:24:44 +00:00
|
|
|
_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
|
2022-04-02 21:14:10 +00:00
|
|
|
char const* filename; // or description
|
2010-10-04 15:24:10 +00:00
|
|
|
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;
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<Buffer> output_buffer;
|
2020-11-29 00:48:07 +00:00
|
|
|
|
|
|
|
// QPDFObjectHandle support
|
2021-12-17 20:30:47 +00:00
|
|
|
bool silence_errors;
|
|
|
|
bool oh_error_occurred;
|
2022-04-09 18:35:56 +00:00
|
|
|
std::map<qpdf_oh, std::shared_ptr<QPDFObjectHandle>> oh_cache;
|
2020-11-29 00:48:07 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
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-17 20:30:47 +00:00
|
|
|
silence_errors(false),
|
|
|
|
oh_error_occurred(false),
|
2020-11-29 00:48:07 +00:00
|
|
|
next_oh(0)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:46:26 +00:00
|
|
|
// must set qpdf->filename and qpdf->password
|
2022-04-02 21:14:10 +00:00
|
|
|
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
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
call_read_memory(qpdf_data qpdf)
|
2010-10-04 15:24:10 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf->qpdf->processMemoryFile(
|
|
|
|
qpdf->filename,
|
|
|
|
qpdf->buffer,
|
|
|
|
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
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
call_init_write(qpdf_data qpdf)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf->qpdf_writer =
|
2022-04-09 18:35:56 +00:00
|
|
|
std::make_shared<QPDFWriter>(*(qpdf->qpdf), qpdf->filename);
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
call_init_write_memory(qpdf_data qpdf)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
2022-04-09 18:35:56 +00:00
|
|
|
qpdf->qpdf_writer = std::make_shared<QPDFWriter>(*(qpdf->qpdf));
|
2011-08-11 15:56:37 +00:00
|
|
|
qpdf->qpdf_writer->setOutputMemory();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
call_check(qpdf_data qpdf)
|
2018-02-17 16:51:10 +00:00
|
|
|
{
|
|
|
|
QPDFWriter w(*qpdf->qpdf);
|
|
|
|
Pl_Discard discard;
|
|
|
|
w.setOutputPipeline(&discard);
|
|
|
|
w.setDecodeLevel(qpdf_dl_all);
|
|
|
|
w.write();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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;
|
2022-04-02 21:14:10 +00:00
|
|
|
try {
|
2022-02-08 14:18:08 +00:00
|
|
|
fn(qpdf);
|
2022-04-02 21:14:10 +00:00
|
|
|
} catch (QPDFExc& e) {
|
2022-04-09 18:35:56 +00:00
|
|
|
qpdf->error = std::make_shared<QPDFExc>(e);
|
2022-02-08 14:18:08 +00:00
|
|
|
status |= QPDF_ERRORS;
|
2022-04-02 21:14:10 +00:00
|
|
|
} catch (std::runtime_error& e) {
|
|
|
|
qpdf->error =
|
2022-04-09 18:35:56 +00:00
|
|
|
std::make_shared<QPDFExc>(qpdf_e_system, "", "", 0, e.what());
|
2022-02-08 14:18:08 +00:00
|
|
|
status |= QPDF_ERRORS;
|
2022-04-02 21:14:10 +00:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
qpdf->error =
|
2022-04-09 18:35:56 +00:00
|
|
|
std::make_shared<QPDFExc>(qpdf_e_internal, "", "", 0, e.what());
|
2022-02-08 14:18:08 +00:00
|
|
|
status |= QPDF_ERRORS;
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf_more_warnings(qpdf)) {
|
2022-02-08 14:18:08 +00:00
|
|
|
status |= QPDF_WARNINGS;
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_qpdf_version()
|
2009-10-24 13:23:20 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version");
|
2022-02-05 13:26:32 +00:00
|
|
|
// The API guarantees that this is a static value.
|
2009-10-24 13:23:20 +00:00
|
|
|
return QPDF::QPDFVersion().c_str();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_data
|
|
|
|
qpdf_init()
|
2009-09-27 03:11:29 +00:00
|
|
|
{
|
2009-09-27 14:39:04 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init");
|
|
|
|
qpdf_data qpdf = new _qpdf_data();
|
2022-09-02 12:53:27 +00:00
|
|
|
qpdf->qpdf = QPDF::create();
|
2009-09-27 14:39:04 +00:00
|
|
|
return qpdf;
|
2009-09-27 03:11:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_cleanup(qpdf_data* qpdf)
|
2009-09-27 03:11:29 +00:00
|
|
|
{
|
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);
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((*qpdf)->error.get()) {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c cleanup warned about unhandled error");
|
2022-06-18 14:33:27 +00:00
|
|
|
*QPDFLogger::defaultLogger()->getWarn()
|
|
|
|
<< "WARNING: application did not handle error: "
|
|
|
|
<< (*qpdf)->error->what() << "\n";
|
2021-12-10 16:09:42 +00:00
|
|
|
}
|
2009-09-27 03:11:29 +00:00
|
|
|
delete *qpdf;
|
2022-07-26 11:37:50 +00:00
|
|
|
*qpdf = nullptr;
|
2009-09-27 03:11:29 +00:00
|
|
|
}
|
2009-09-27 14:39:04 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
size_t
|
|
|
|
qpdf_get_last_string_length(qpdf_data qpdf)
|
2021-12-02 12:54:33 +00:00
|
|
|
{
|
|
|
|
return qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_more_warnings(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_more_warnings");
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->warnings.empty()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
std::vector<QPDFExc> w = qpdf->qpdf->getWarnings();
|
2022-04-02 21:14:10 +00:00
|
|
|
if (!w.empty()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->warnings.assign(w.begin(), w.end());
|
|
|
|
}
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->warnings.empty()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return QPDF_FALSE;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-02-08 14:18:08 +00:00
|
|
|
return QPDF_TRUE;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_has_error(qpdf_data qpdf)
|
2009-10-23 15:27:30 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_has_error");
|
2022-02-04 15:10:19 +00:00
|
|
|
return (qpdf->error.get() ? QPDF_TRUE : QPDF_FALSE);
|
2009-10-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_error
|
|
|
|
qpdf_get_error(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->error.get()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->tmp_error.exc = qpdf->error;
|
2022-07-26 11:37:50 +00:00
|
|
|
qpdf->error = nullptr;
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");
|
|
|
|
return &qpdf->tmp_error;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-07-26 11:37:50 +00:00
|
|
|
return nullptr;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_error
|
|
|
|
qpdf_next_warning(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf_more_warnings(qpdf)) {
|
2022-04-09 18:35:56 +00:00
|
|
|
qpdf->tmp_error.exc = std::make_shared<QPDFExc>(qpdf->warnings.front());
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->warnings.pop_front();
|
|
|
|
QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");
|
|
|
|
return &qpdf->tmp_error;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-07-26 11:37:50 +00:00
|
|
|
return nullptr;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (e == nullptr) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return "";
|
2009-10-23 16:50:22 +00:00
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->what();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
enum qpdf_error_code_e
|
|
|
|
qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (e == nullptr) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return qpdf_e_success;
|
2009-10-23 16:50:22 +00:00
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getErrorCode();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (e == nullptr) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return "";
|
2009-10-23 16:50:22 +00:00
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getFilename().c_str();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
unsigned long long
|
|
|
|
qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (e == nullptr) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return 0;
|
2009-10-23 16:50:22 +00:00
|
|
|
}
|
2019-06-21 03:35:23 +00:00
|
|
|
return QIntC::to_ulonglong(e->exc->getFilePosition());
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
|
2009-10-20 00:24:44 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (e == nullptr) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return "";
|
2009-10-23 16:50:22 +00:00
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return e->exc->getMessageDetail().c_str();
|
2009-10-20 00:24:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_check_pdf(qpdf_data qpdf)
|
2018-02-17 16:51:10 +00:00
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = trap_errors(qpdf, &call_check);
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_check_pdf");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2022-09-09 12:03:21 +00:00
|
|
|
void
|
|
|
|
qpdf_set_logger(qpdf_data qpdf, qpdflogger_handle logger)
|
|
|
|
{
|
|
|
|
qpdf->qpdf->setLogger(logger->l);
|
|
|
|
}
|
|
|
|
|
|
|
|
qpdflogger_handle
|
|
|
|
qpdf_get_logger(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
return new _qpdflogger_handle(qpdf->qpdf->getLogger());
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_suppress_warnings(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_ignore_xref_streams(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_attempt_recovery(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_read(qpdf_data qpdf, char const* filename, char const* password)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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.
|
2022-04-02 21:14:10 +00:00
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"qpdf-c called qpdf_read",
|
|
|
|
(status == 0) ? 0
|
2017-07-26 18:38:49 +00:00
|
|
|
: (status & QPDF_WARNINGS) ? 1
|
2022-04-02 21:14:10 +00:00
|
|
|
: (status & QPDF_ERRORS) ? 2
|
|
|
|
: -1);
|
2009-09-27 14:39:04 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_read_memory(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
char const* description,
|
|
|
|
char const* buffer,
|
|
|
|
unsigned long long size,
|
|
|
|
char const* password)
|
2010-10-04 15:24:10 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_empty_pdf(qpdf_data qpdf)
|
2022-02-05 13:50:39 +00:00
|
|
|
{
|
|
|
|
qpdf->filename = "empty PDF";
|
|
|
|
qpdf->qpdf->emptyPDF();
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_empty_pdf");
|
|
|
|
return QPDF_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_pdf_version(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_pdf_version");
|
|
|
|
qpdf->tmp_string = qpdf->qpdf->getPDFVersion();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_get_pdf_extension_level(qpdf_data qpdf)
|
2012-12-31 11:47:11 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_pdf_extension_level");
|
|
|
|
return qpdf->qpdf->getExtensionLevel();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_user_password(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_user_password");
|
|
|
|
qpdf->tmp_string = qpdf->qpdf->getTrimmedUserPassword();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_get_info_key(qpdf_data qpdf, char const* key)
|
2011-08-11 14:48:37 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
char const* result = nullptr;
|
2011-08-11 14:48:37 +00:00
|
|
|
QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
|
2022-04-02 21:14:10 +00:00
|
|
|
if (trailer.hasKey("/Info")) {
|
2022-02-08 14:18:08 +00:00
|
|
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
2022-04-02 21:14:10 +00:00
|
|
|
if (info.hasKey(key)) {
|
2022-02-08 14:18:08 +00:00
|
|
|
QPDFObjectHandle value = info.getKey(key);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (value.isString()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->tmp_string = value.getStringValue();
|
|
|
|
result = qpdf->tmp_string.c_str();
|
|
|
|
}
|
|
|
|
}
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
2022-07-26 11:37:50 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c get_info_key", (result == nullptr ? 0 : 1));
|
2011-08-11 14:48:37 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value)
|
2011-08-11 14:48:37 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if ((key == nullptr) || (std::strlen(key) == 0) || (key[0] != '/')) {
|
2022-02-08 14:18:08 +00:00
|
|
|
return;
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
|
|
|
QPDFObjectHandle value_object;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (value) {
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c set_info_key to value");
|
|
|
|
value_object = QPDFObjectHandle::newString(value);
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c set_info_key to null");
|
|
|
|
value_object = QPDFObjectHandle::newNull();
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle trailer = qpdf->qpdf->getTrailer();
|
2022-04-02 21:14:10 +00:00
|
|
|
if (!trailer.hasKey("/Info")) {
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c add info to trailer");
|
|
|
|
trailer.replaceKey(
|
|
|
|
"/Info",
|
|
|
|
qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c set-info-key use existing info");
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPDFObjectHandle info = trailer.getKey("/Info");
|
2022-04-24 13:31:32 +00:00
|
|
|
info.replaceKey(key, value_object);
|
2011-08-11 14:48:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_is_linearized(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_is_linearized");
|
|
|
|
return (qpdf->qpdf->isLinearized() ? QPDF_TRUE : QPDF_FALSE);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_is_encrypted(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_is_encrypted");
|
|
|
|
return (qpdf->qpdf->isEncrypted() ? QPDF_TRUE : QPDF_FALSE);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_accessibility(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_extract_all(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_print_low_res(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_print_high_res(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_modify_assembly(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_modify_form(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_modify_annotation(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_modify_other(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_allow_modify_all(qpdf_data qpdf)
|
2009-09-27 20:05:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
qpdf_init_write_internal(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->qpdf_writer.get()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");
|
2022-07-26 11:37:50 +00:00
|
|
|
qpdf->qpdf_writer = nullptr;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->output_buffer.get()) {
|
2022-07-26 11:37:50 +00:00
|
|
|
qpdf->output_buffer = nullptr;
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->write_memory = false;
|
2022-07-26 11:37:50 +00:00
|
|
|
qpdf->filename = nullptr;
|
2022-02-08 14:18:08 +00:00
|
|
|
}
|
2009-10-20 00:46:26 +00:00
|
|
|
}
|
2011-08-11 15:56:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_init_write(qpdf_data qpdf, char const* filename)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_init_write_memory(qpdf_data qpdf)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
qpdf_get_buffer_internal(qpdf_data qpdf)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
if (qpdf->write_memory && (qpdf->output_buffer == nullptr)) {
|
2022-02-08 14:18:08 +00:00
|
|
|
qpdf->output_buffer = qpdf->qpdf_writer->getBufferSharedPointer();
|
2011-08-11 15:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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;
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->output_buffer.get()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
result = qpdf->output_buffer->getSize();
|
2011-08-11 15:56:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
unsigned char const*
|
|
|
|
qpdf_get_buffer(qpdf_data qpdf)
|
2011-08-11 15:56:37 +00:00
|
|
|
{
|
2022-07-26 11:37:50 +00:00
|
|
|
unsigned char const* result = nullptr;
|
2011-08-11 15:56:37 +00:00
|
|
|
qpdf_get_buffer_internal(qpdf);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf->output_buffer.get()) {
|
2022-02-08 14:18:08 +00:00
|
|
|
result = qpdf->output_buffer->getBuffer();
|
2011-08-11 15:56:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_compress_streams(qpdf_data qpdf, QPDF_BOOL value)
|
2017-09-12 00:11:10 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_decode_level(qpdf_data qpdf, qpdf_stream_decode_level_e level)
|
2017-09-12 00:11:10 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_decode_level");
|
|
|
|
qpdf->qpdf_writer->setDecodeLevel(level);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_preserve_unreferenced_objects(qpdf_data qpdf, QPDF_BOOL value)
|
2017-09-12 00:11:10 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value)
|
2017-09-12 00:11:10 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_content_normalization(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_qdf_mode(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_deterministic_ID(qpdf_data qpdf, QPDF_BOOL value)
|
2015-10-25 15:09:25 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_static_ID(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_static_aes_IV(qpdf_data qpdf, QPDF_BOOL value)
|
2009-10-19 00:36:51 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_suppress_original_object_IDs(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
2022-04-30 20:05:28 +00:00
|
|
|
qpdf_set_r2_encryption_parameters_insecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
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)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
2022-04-30 20:05:28 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r2_encryption_parameters_insecure");
|
|
|
|
qpdf->qpdf_writer->setR2EncryptionParametersInsecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
user_password,
|
|
|
|
owner_password,
|
|
|
|
allow_print != QPDF_FALSE,
|
|
|
|
allow_modify != QPDF_FALSE,
|
|
|
|
allow_extract != QPDF_FALSE,
|
|
|
|
allow_annotate != QPDF_FALSE);
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
2022-04-30 20:05:28 +00:00
|
|
|
qpdf_set_r3_encryption_parameters_insecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
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,
|
2019-01-15 01:45:08 +00:00
|
|
|
enum qpdf_r3_print_e print)
|
|
|
|
{
|
2022-04-30 20:05:28 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters_insecure");
|
|
|
|
qpdf->qpdf_writer->setR3EncryptionParametersInsecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
user_password,
|
|
|
|
owner_password,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
2022-04-30 20:05:28 +00:00
|
|
|
qpdf_set_r4_encryption_parameters_insecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
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,
|
2019-01-15 01:45:08 +00:00
|
|
|
enum qpdf_r3_print_e print,
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL encrypt_metadata,
|
|
|
|
QPDF_BOOL use_aes)
|
2019-01-15 01:45:08 +00:00
|
|
|
{
|
2022-04-30 20:05:28 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters_insecure");
|
|
|
|
qpdf->qpdf_writer->setR4EncryptionParametersInsecure(
|
2022-04-02 21:14:10 +00:00
|
|
|
user_password,
|
|
|
|
owner_password,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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)
|
2019-01-15 01:45:08 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR5EncryptionParameters(
|
2022-04-02 21:14:10 +00:00
|
|
|
user_password,
|
|
|
|
owner_password,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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)
|
2019-01-15 01:45:08 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR6EncryptionParameters(
|
2022-04-02 21:14:10 +00:00
|
|
|
user_password,
|
|
|
|
owner_password,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_linearization(qpdf_data qpdf, QPDF_BOOL value)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_set_minimum_pdf_version_and_extension(
|
2012-12-31 11:47:11 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +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);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_force_pdf_version_and_extension(
|
2012-12-31 11:47:11 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_register_progress_reporter(
|
2020-12-20 19:43:08 +00:00
|
|
|
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(
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<QPDFWriter::ProgressReporter>(
|
2022-06-18 18:56:58 +00:00
|
|
|
new QPDFWriter::FunctionProgressReporter(
|
|
|
|
std::bind(report_progress, std::placeholders::_1, data))));
|
2020-12-20 19:43:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_write(qpdf_data qpdf)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_silence_errors(qpdf_data qpdf)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
2021-12-17 20:30:47 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c silence oh errors");
|
|
|
|
qpdf->silence_errors = true;
|
2021-12-10 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
template <class RET>
|
|
|
|
static RET
|
|
|
|
trap_oh_errors(
|
2021-12-10 16:09:42 +00:00
|
|
|
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;
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE status =
|
|
|
|
trap_errors(qpdf, [&ret, fn](qpdf_data q) { ret = fn(q); });
|
|
|
|
if (status & QPDF_ERRORS) {
|
|
|
|
if (!qpdf->silence_errors) {
|
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"qpdf-c warn about oh error",
|
|
|
|
qpdf->oh_error_occurred ? 0 : 1);
|
|
|
|
if (!qpdf->oh_error_occurred) {
|
|
|
|
qpdf->warnings.push_back(QPDFExc(
|
|
|
|
qpdf_e_internal,
|
|
|
|
qpdf->qpdf->getFilename(),
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
"C API function caught an exception that it isn't"
|
|
|
|
" returning; please point the application developer"
|
|
|
|
" to ERROR HANDLING in qpdf-c.h"));
|
2021-12-17 20:30:47 +00:00
|
|
|
qpdf->oh_error_occurred = true;
|
|
|
|
}
|
2022-06-18 14:33:27 +00:00
|
|
|
*QPDFLogger::defaultLogger()->getError()
|
|
|
|
<< qpdf->error->what() << "\n";
|
2021-12-17 20:30:47 +00:00
|
|
|
}
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
2022-04-09 18:35:56 +00:00
|
|
|
qpdf->oh_cache[oh] = std::make_shared<QPDFObjectHandle>(qoh);
|
2020-11-29 00:48:07 +00:00
|
|
|
return oh;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_object(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-02 16:47:04 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_new_object");
|
|
|
|
return new_object(qpdf, *(qpdf->oh_cache[oh]));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_release(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_release");
|
|
|
|
qpdf->oh_cache.erase(oh);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_release_all(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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>
|
2022-04-02 21:14:10 +00:00
|
|
|
static std::function<T()>
|
|
|
|
return_T(T const& r)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
return [&r]() { return r; };
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static QPDF_BOOL
|
|
|
|
return_false()
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
return QPDF_FALSE;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static std::function<qpdf_oh()>
|
|
|
|
return_uninitialized(qpdf_data qpdf)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
return [qpdf]() { return qpdf_oh_new_uninitialized(qpdf); };
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static std::function<qpdf_oh()>
|
|
|
|
return_null(qpdf_data qpdf)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
return [qpdf]() { return qpdf_oh_new_null(qpdf); };
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_get_trailer(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_trailer");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
|
2021-12-10 16:09:42 +00:00
|
|
|
return new_object(q, q->qpdf->getTrailer());
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_get_root(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_root");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, return_uninitialized(qpdf), [](qpdf_data q) {
|
2021-12-10 16:09:42 +00:00
|
|
|
return new_object(q, q->qpdf->getRoot());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_get_object_by_id(qpdf_data qpdf, int objid, int generation)
|
2021-12-10 19:57:11 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_object_by_id");
|
|
|
|
return new_object(qpdf, qpdf->qpdf->getObjectByID(objid, generation));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
template <class RET>
|
|
|
|
static RET
|
|
|
|
do_with_oh(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
qpdf_oh oh,
|
2021-12-10 16:09:42 +00:00
|
|
|
std::function<RET()> fallback,
|
|
|
|
std::function<RET(QPDFObjectHandle&)> fn)
|
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
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).get());
|
|
|
|
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]));
|
|
|
|
});
|
2021-12-10 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
do_with_oh_void(
|
|
|
|
qpdf_data qpdf, qpdf_oh oh, std::function<void(QPDFObjectHandle&)> fn)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
do_with_oh<bool>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<bool>(false), [fn](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
fn(o);
|
|
|
|
return true; // unused
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_replace_object(qpdf_data qpdf, int objid, int generation, qpdf_oh oh)
|
2021-12-10 19:57:11 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
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-10 19:57:11 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-02 13:04:59 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_bool(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_bool");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isBool(); });
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_null(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_null");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isNull(); });
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_integer(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_real(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_real");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isReal(); });
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_name(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name");
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, oh, return_false, [](QPDFObjectHandle& o) { return o.isName(); });
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_string(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_operator(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_inline_image(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_array(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_dictionary(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_stream(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_indirect(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_scalar(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_number(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_is_number");
|
|
|
|
return o.isNumber();
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_name_and_equals(qpdf_data qpdf, qpdf_oh oh, char const* name)
|
2022-01-21 14:09:06 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [name](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_name_and_equals");
|
|
|
|
return o.isNameAndEquals(name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_dictionary_of_type(
|
2022-01-22 14:14:53 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const* type, char const* subtype)
|
2022-01-21 14:09:06 +00:00
|
|
|
{
|
|
|
|
auto stype = (subtype == nullptr) ? "" : subtype;
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [type, stype](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_dictionary_of_type");
|
|
|
|
return o.isDictionaryOfType(type, stype);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_object_type_e
|
|
|
|
qpdf_oh_get_type_code(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-17 16:47:22 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<qpdf_object_type_e>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
oh,
|
|
|
|
return_T<qpdf_object_type_e>(ot_uninitialized),
|
2021-12-17 16:47:22 +00:00
|
|
|
[](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_type_code");
|
|
|
|
return o.getTypeCode();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_type_name(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-17 16:47:22 +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_type_name");
|
|
|
|
qpdf->tmp_string = o.getTypeName();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_wrap_in_array(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
oh,
|
|
|
|
[qpdf]() { return qpdf_oh_new_array(qpdf); },
|
2021-12-16 16:01:06 +00:00
|
|
|
[qpdf](QPDFObjectHandle& qoh) {
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qoh.isArray()) {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c array to wrap_in_array");
|
|
|
|
return new_object(qpdf, qoh);
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c non-array to wrap_in_array");
|
2022-04-02 21:14:10 +00:00
|
|
|
return new_object(
|
|
|
|
qpdf,
|
|
|
|
QPDFObjectHandle::newArray(
|
|
|
|
std::vector<QPDFObjectHandle>{qoh}));
|
2021-12-10 16:09:42 +00:00
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_parse(qpdf_data qpdf, char const* object_str)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_parse");
|
2021-12-10 16:09:42 +00:00
|
|
|
return trap_oh_errors<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, return_uninitialized(qpdf), [object_str](qpdf_data q) {
|
2021-12-10 16:09:42 +00:00
|
|
|
return new_object(q, QPDFObjectHandle::parse(object_str));
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_bool_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_bool(qpdf_data qpdf, qpdf_oh oh, QPDF_BOOL* value)
|
2022-02-05 20:08:58 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_bool");
|
|
|
|
bool v = *value;
|
|
|
|
QPDF_BOOL result = o.getValueAsBool(v);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (result) {
|
2022-02-05 20:08:58 +00:00
|
|
|
*value = v;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
long long
|
|
|
|
qpdf_oh_get_int_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_longlong(qpdf_data qpdf, qpdf_oh oh, long long* value)
|
2022-02-05 20:08:58 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_longlong");
|
|
|
|
return o.getValueAsInt(*value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_oh_get_int_value_as_int(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_int(qpdf_data qpdf, qpdf_oh oh, int* value)
|
2022-02-05 20:08:58 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_int");
|
|
|
|
return o.getValueAsInt(*value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
unsigned long long
|
|
|
|
qpdf_oh_get_uint_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_ulonglong(
|
2022-02-05 20:08:58 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, unsigned long long* value)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_ulonglong");
|
|
|
|
return o.getValueAsUInt(*value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
unsigned int
|
|
|
|
qpdf_oh_get_uint_value_as_uint(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_uint(qpdf_data qpdf, qpdf_oh oh, unsigned int* value)
|
2022-02-05 20:08:58 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_uint");
|
|
|
|
return o.getValueAsUInt(*value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_real_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_real(
|
2022-02-05 20:08:58 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_real");
|
|
|
|
auto result = o.getValueAsReal(qpdf->tmp_string);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (result) {
|
2022-02-05 20:08:58 +00:00
|
|
|
*value = qpdf->tmp_string.c_str();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
double
|
|
|
|
qpdf_oh_get_numeric_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_number(qpdf_data qpdf, qpdf_oh oh, double* value)
|
2022-02-05 20:08:58 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [value](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_number");
|
|
|
|
return o.getValueAsNumber(*value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_name(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_name(
|
2022-02-05 20:08:58 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_name");
|
|
|
|
auto result = o.getValueAsName(qpdf->tmp_string);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (result) {
|
2022-02-05 20:08:58 +00:00
|
|
|
*value = qpdf->tmp_string.c_str();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_string_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_string(
|
2022-02-05 20:08:58 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_string");
|
|
|
|
auto result = o.getValueAsString(qpdf->tmp_string);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (result) {
|
2022-02-05 20:08:58 +00:00
|
|
|
*value = qpdf->tmp_string.c_str();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_utf8_value(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_get_value_as_utf8(
|
2022-02-05 20:08:58 +00:00
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const** value, size_t* length)
|
|
|
|
{
|
|
|
|
return do_with_oh<QPDF_BOOL>(
|
|
|
|
qpdf, oh, return_false, [qpdf, value, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_value_as_utf8");
|
|
|
|
auto result = o.getValueAsUTF8(qpdf->tmp_string);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (result) {
|
2022-02-05 20:08:58 +00:00
|
|
|
*value = qpdf->tmp_string.c_str();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_binary_string_value(qpdf_data qpdf, qpdf_oh oh, size_t* length)
|
2021-12-19 18:52:19 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<char const*>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
oh,
|
2021-12-19 18:52:19 +00:00
|
|
|
return_T<char const*>(""),
|
|
|
|
[qpdf, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_string_value");
|
|
|
|
qpdf->tmp_string = o.getStringValue();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_get_binary_utf8_value(qpdf_data qpdf, qpdf_oh oh, size_t* length)
|
2022-02-04 17:15:34 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<char const*>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
oh,
|
2022-02-04 17:15:34 +00:00
|
|
|
return_T<char const*>(""),
|
|
|
|
[qpdf, length](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_binary_utf8_value");
|
|
|
|
qpdf->tmp_string = o.getUTF8Value();
|
|
|
|
*length = qpdf->tmp_string.length();
|
|
|
|
return qpdf->tmp_string.c_str();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_oh_get_array_n_items(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_get_array_item(qpdf_data qpdf, qpdf_oh oh, int n)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_null(qpdf), [qpdf, n](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_begin_dict_key_iter(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
qpdf->cur_iter_dict_keys = do_with_oh<std::set<std::string>>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
oh,
|
|
|
|
[]() { return std::set<std::string>(); },
|
2021-12-10 16:09:42 +00:00
|
|
|
[](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();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_dict_more_keys(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_dict_more_keys");
|
|
|
|
return qpdf->dict_iter != qpdf->cur_iter_dict_keys.end();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_dict_next_key(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_dict_next_key");
|
2022-04-02 21:14:10 +00:00
|
|
|
if (qpdf_oh_dict_more_keys(qpdf)) {
|
2020-11-29 00:48:07 +00:00
|
|
|
qpdf->cur_dict_key = *qpdf->dict_iter;
|
|
|
|
++qpdf->dict_iter;
|
|
|
|
return qpdf->cur_dict_key.c_str();
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2020-11-29 00:48:07 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_has_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_has_key");
|
|
|
|
return o.hasKey(key);
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_get_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_null(qpdf), [qpdf, key](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_get_key_if_dict(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
2022-02-06 06:37:20 +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_if_dict");
|
|
|
|
return new_object(qpdf, o.getKeyIfDict(key));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_BOOL
|
|
|
|
qpdf_oh_is_or_has_name(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<QPDF_BOOL>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_false, [key](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_or_has_name");
|
|
|
|
return o.isOrHasName(key);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_uninitialized(qpdf_data qpdf)
|
2021-12-10 16:09:42 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_uninitialized");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle());
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_null(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_null");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newNull());
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_bool(qpdf_data qpdf, QPDF_BOOL value)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_bool");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newBool(value));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_integer(qpdf_data qpdf, long long value)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_integer");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newInteger(value));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_real_from_string(qpdf_data qpdf, char const* value)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_real_from_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newReal(value));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_real_from_double(qpdf_data qpdf, double value, int decimal_places)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_real_from_double");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newReal(value, decimal_places));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_name(qpdf_data qpdf, char const* name)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_name");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newName(name));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_string(qpdf_data qpdf, char const* str)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newString(str));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_unicode_string(qpdf_data qpdf, char const* utf8_str)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_unicode_string");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newUnicodeString(utf8_str));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_binary_string(qpdf_data qpdf, char const* str, size_t length)
|
2021-12-19 18:52:19 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_string");
|
|
|
|
return new_object(
|
|
|
|
qpdf, QPDFObjectHandle::newString(std::string(str, length)));
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_binary_unicode_string(
|
2022-02-04 17:15:34 +00:00
|
|
|
qpdf_data qpdf, char const* utf8_str, size_t length)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_binary_unicode_string");
|
|
|
|
return new_object(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
QPDFObjectHandle::newUnicodeString(std::string(utf8_str, length)));
|
2022-02-04 17:15:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_array(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_array");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newArray());
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_dictionary(qpdf_data qpdf)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_dictionary");
|
|
|
|
return new_object(qpdf, QPDFObjectHandle::newDictionary());
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_new_stream(qpdf_data qpdf)
|
2021-12-17 18:28:11 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_new_stream");
|
2022-04-02 21:14:10 +00:00
|
|
|
return new_object(qpdf, QPDFObjectHandle::newStream(qpdf->qpdf.get()));
|
2021-12-17 18:28:11 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_make_direct(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_make_indirect_object(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-10 19:57:11 +00:00
|
|
|
{
|
|
|
|
return do_with_oh<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf, oh, return_uninitialized(qpdf), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 19:57:11 +00:00
|
|
|
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>(
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf,
|
|
|
|
item,
|
|
|
|
[]() { return QPDFObjectHandle::newNull(); },
|
|
|
|
[](QPDFObjectHandle& o) { return o; });
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_set_array_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_insert_item(qpdf_data qpdf, qpdf_oh oh, int at, qpdf_oh item)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_append_item(qpdf_data qpdf, qpdf_oh oh, qpdf_oh item)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_erase_item(qpdf_data qpdf, qpdf_oh oh, int at)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_replace_key(qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_remove_key(qpdf_data qpdf, qpdf_oh oh, char const* key)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_replace_or_remove_key(
|
|
|
|
qpdf_data qpdf, qpdf_oh oh, char const* key, qpdf_oh item)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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");
|
2022-04-24 13:31:32 +00:00
|
|
|
o.replaceKey(key, qpdf_oh_item_internal(qpdf, item));
|
2022-04-02 21:14:10 +00:00
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_get_dict(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<qpdf_oh>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_null(qpdf), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_dict");
|
|
|
|
return new_object(qpdf, o.getDict());
|
|
|
|
});
|
2020-11-29 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_oh_get_object_id(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_oh_get_generation(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_unparse(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_unparse_resolved(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
char const*
|
|
|
|
qpdf_oh_unparse_binary(qpdf_data qpdf, qpdf_oh oh)
|
2020-11-29 00:48:07 +00:00
|
|
|
{
|
2021-12-10 16:09:42 +00:00
|
|
|
return do_with_oh<char const*>(
|
2021-12-16 16:01:06 +00:00
|
|
|
qpdf, oh, return_T<char const*>(""), [qpdf](QPDFObjectHandle& o) {
|
2021-12-10 16:09:42 +00:00
|
|
|
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
|
|
|
}
|
2021-12-16 19:36:21 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_oh_copy_foreign_object(
|
2021-12-17 18:28:11 +00:00
|
|
|
qpdf_data qpdf, qpdf_data other_qpdf, qpdf_oh foreign_oh)
|
|
|
|
{
|
|
|
|
return do_with_oh<qpdf_oh>(
|
2022-04-02 21:14:10 +00:00
|
|
|
other_qpdf,
|
|
|
|
foreign_oh,
|
2021-12-17 18:28:11 +00:00
|
|
|
return_uninitialized(qpdf),
|
|
|
|
[qpdf](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_copy_foreign_object");
|
|
|
|
return new_object(qpdf, qpdf->qpdf->copyForeignObject(o));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_oh_get_stream_data(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
qpdf_oh stream_oh,
|
|
|
|
qpdf_stream_decode_level_e decode_level,
|
|
|
|
QPDF_BOOL* filtered,
|
|
|
|
unsigned char** bufp,
|
|
|
|
size_t* len)
|
|
|
|
{
|
|
|
|
return trap_errors(
|
|
|
|
qpdf, [stream_oh, decode_level, filtered, bufp, len](qpdf_data q) {
|
|
|
|
auto stream = qpdf_oh_item_internal(q, stream_oh);
|
|
|
|
Pipeline* p = nullptr;
|
|
|
|
Pl_Buffer buf("stream data");
|
|
|
|
if (bufp) {
|
|
|
|
p = &buf;
|
2021-12-17 18:28:11 +00:00
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
bool was_filtered = false;
|
|
|
|
if (stream.pipeStreamData(
|
|
|
|
p, &was_filtered, 0, decode_level, false, false)) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c stream data buf set", bufp ? 0 : 1);
|
|
|
|
if (p && bufp && len) {
|
|
|
|
buf.getMallocBuffer(bufp, len);
|
|
|
|
}
|
|
|
|
QTC::TC(
|
|
|
|
"qpdf",
|
|
|
|
"qpdf-c stream data filtered set",
|
2021-12-17 18:28:11 +00:00
|
|
|
filtered ? 0 : 1);
|
2022-04-02 21:14:10 +00:00
|
|
|
if (filtered) {
|
|
|
|
*filtered = was_filtered ? QPDF_TRUE : QPDF_FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error(
|
|
|
|
"unable to access stream data for stream " +
|
|
|
|
stream.unparse());
|
2021-12-17 18:28:11 +00:00
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
});
|
2021-12-17 18:28:11 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_oh_get_page_content_data(
|
|
|
|
qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len)
|
2021-12-17 18:28:11 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +00:00
|
|
|
return trap_errors(qpdf, [page_oh, bufp, len](qpdf_data q) {
|
2021-12-17 18:28:11 +00:00
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_get_page_content_data");
|
|
|
|
auto o = qpdf_oh_item_internal(q, page_oh);
|
|
|
|
Pl_Buffer buf("page contents");
|
|
|
|
o.pipePageContents(&buf);
|
|
|
|
buf.getMallocBuffer(bufp, len);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
qpdf_oh_replace_stream_data(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
qpdf_oh stream_oh,
|
|
|
|
unsigned char const* buf,
|
|
|
|
size_t len,
|
|
|
|
qpdf_oh filter_oh,
|
|
|
|
qpdf_oh decode_parms_oh)
|
|
|
|
{
|
|
|
|
do_with_oh_void(
|
|
|
|
qpdf,
|
|
|
|
stream_oh,
|
|
|
|
[qpdf, buf, len, filter_oh, decode_parms_oh](QPDFObjectHandle& o) {
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_stream_data");
|
|
|
|
auto filter = qpdf_oh_item_internal(qpdf, filter_oh);
|
|
|
|
auto decode_parms = qpdf_oh_item_internal(qpdf, decode_parms_oh);
|
|
|
|
// XXX test with binary data with null
|
|
|
|
o.replaceStreamData(
|
|
|
|
std::string(reinterpret_cast<char const*>(buf), len),
|
|
|
|
filter,
|
|
|
|
decode_parms);
|
|
|
|
});
|
2021-12-17 18:28:11 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_get_num_pages(qpdf_data qpdf)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_num_pages");
|
|
|
|
int n = -1;
|
|
|
|
QPDF_ERROR_CODE code = trap_errors(qpdf, [&n](qpdf_data q) {
|
|
|
|
n = QIntC::to_int(q->qpdf->getAllPages().size());
|
|
|
|
});
|
2022-04-02 21:14:10 +00:00
|
|
|
if (code & QPDF_ERRORS) {
|
2021-12-16 19:36:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
qpdf_oh
|
|
|
|
qpdf_get_page_n(qpdf_data qpdf, size_t i)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_get_page_n");
|
|
|
|
qpdf_oh result = 0;
|
|
|
|
QPDF_ERROR_CODE code = trap_errors(qpdf, [&result, i](qpdf_data q) {
|
|
|
|
result = new_object(q, q->qpdf->getAllPages().at(i));
|
|
|
|
});
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((code & QPDF_ERRORS) || (result == 0)) {
|
2021-12-16 19:36:21 +00:00
|
|
|
return qpdf_oh_new_uninitialized(qpdf);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_update_all_pages_cache(qpdf_data qpdf)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_update_all_pages_cache");
|
2022-04-02 21:14:10 +00:00
|
|
|
return trap_errors(
|
|
|
|
qpdf, [](qpdf_data q) { q->qpdf->updateAllPagesCache(); });
|
2021-12-16 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_find_page_by_id(qpdf_data qpdf, int objid, int generation)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_id");
|
|
|
|
int n = -1;
|
|
|
|
QPDFObjGen og(objid, generation);
|
|
|
|
QPDF_ERROR_CODE code = trap_errors(qpdf, [&n, &og](qpdf_data q) {
|
|
|
|
n = QIntC::to_int(q->qpdf->findPage(og));
|
|
|
|
});
|
2022-04-02 21:14:10 +00:00
|
|
|
if (code & QPDF_ERRORS) {
|
2021-12-16 19:36:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
qpdf_find_page_by_oh(qpdf_data qpdf, qpdf_oh oh)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_find_page_by_oh");
|
|
|
|
return do_with_oh<int>(
|
|
|
|
qpdf, oh, return_T<int>(-1), [qpdf](QPDFObjectHandle& o) {
|
|
|
|
return qpdf->qpdf->findPage(o);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_push_inherited_attributes_to_page(qpdf_data qpdf)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_push_inherited_attributes_to_page");
|
2022-04-02 21:14:10 +00:00
|
|
|
return trap_errors(
|
|
|
|
qpdf, [](qpdf_data q) { q->qpdf->pushInheritedAttributesToPage(); });
|
2021-12-16 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_add_page(
|
2021-12-16 19:36:21 +00:00
|
|
|
qpdf_data qpdf, qpdf_data newpage_qpdf, qpdf_oh newpage, QPDF_BOOL first)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_add_page");
|
|
|
|
auto page = qpdf_oh_item_internal(newpage_qpdf, newpage);
|
2022-04-02 21:14:10 +00:00
|
|
|
return trap_errors(
|
|
|
|
qpdf, [&page, first](qpdf_data q) { q->qpdf->addPage(page, first); });
|
2021-12-16 19:36:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_add_page_at(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
qpdf_data newpage_qpdf,
|
|
|
|
qpdf_oh newpage,
|
|
|
|
QPDF_BOOL before,
|
|
|
|
qpdf_oh refpage)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_add_page_at");
|
|
|
|
auto page = qpdf_oh_item_internal(newpage_qpdf, newpage);
|
|
|
|
auto ref = qpdf_oh_item_internal(qpdf, refpage);
|
|
|
|
return trap_errors(qpdf, [&page, before, &ref](qpdf_data q) {
|
|
|
|
q->qpdf->addPageAt(page, before, ref);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_remove_page(qpdf_data qpdf, qpdf_oh page)
|
2021-12-16 19:36:21 +00:00
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_remove_page");
|
|
|
|
auto p = qpdf_oh_item_internal(qpdf, page);
|
2022-04-02 21:14:10 +00:00
|
|
|
return trap_errors(qpdf, [&p](qpdf_data q) { q->qpdf->removePage(p); });
|
2021-12-16 19:36:21 +00:00
|
|
|
}
|
2022-09-08 19:57:33 +00:00
|
|
|
|
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_create_from_json_file(qpdf_data qpdf, char const* filename)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
qpdf->filename = filename;
|
|
|
|
status = trap_errors(
|
|
|
|
qpdf, [](qpdf_data q) { q->qpdf->createFromJSON(q->filename); });
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_create_from_json_data(
|
|
|
|
qpdf_data qpdf, char const* buffer, unsigned long long size)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
qpdf->filename = "json buffer";
|
|
|
|
qpdf->buffer = buffer;
|
|
|
|
qpdf->size = size;
|
|
|
|
auto b =
|
|
|
|
new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
|
|
|
|
auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true);
|
|
|
|
status =
|
|
|
|
trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->createFromJSON(is); });
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_update_from_json_file(qpdf_data qpdf, char const* filename)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
status = trap_errors(
|
|
|
|
qpdf, [filename](qpdf_data q) { q->qpdf->updateFromJSON(filename); });
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_update_from_json_data(
|
|
|
|
qpdf_data qpdf, char const* buffer, unsigned long long size)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
auto b =
|
|
|
|
new Buffer(QUtil::unsigned_char_pointer(buffer), QIntC::to_size(size));
|
|
|
|
auto is = std::make_shared<BufferInputSource>(qpdf->filename, b, true);
|
|
|
|
status =
|
|
|
|
trap_errors(qpdf, [&is](qpdf_data q) { q->qpdf->updateFromJSON(is); });
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_ERROR_CODE
|
|
|
|
qpdf_write_json(
|
|
|
|
qpdf_data qpdf,
|
|
|
|
int version,
|
|
|
|
qpdf_write_fn_t fn,
|
|
|
|
void* udata,
|
|
|
|
enum qpdf_stream_decode_level_e decode_level,
|
|
|
|
enum qpdf_json_stream_data_e json_stream_data,
|
|
|
|
char const* file_prefix,
|
|
|
|
char const* const* wanted_objects)
|
|
|
|
{
|
|
|
|
QPDF_ERROR_CODE status = QPDF_SUCCESS;
|
|
|
|
auto p = std::make_shared<Pl_Function>("write_json", nullptr, fn, udata);
|
|
|
|
std::set<std::string> wanted_objects_set;
|
|
|
|
if (wanted_objects) {
|
|
|
|
for (auto i = wanted_objects; *i; ++i) {
|
|
|
|
wanted_objects_set.insert(*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status = trap_errors(
|
|
|
|
qpdf,
|
|
|
|
[version,
|
|
|
|
p,
|
|
|
|
decode_level,
|
|
|
|
json_stream_data,
|
|
|
|
file_prefix,
|
|
|
|
&wanted_objects_set](qpdf_data q) {
|
|
|
|
q->qpdf->writeJSON(
|
|
|
|
version,
|
|
|
|
p.get(),
|
|
|
|
decode_level,
|
|
|
|
json_stream_data,
|
|
|
|
file_prefix,
|
|
|
|
wanted_objects_set);
|
|
|
|
});
|
|
|
|
return status;
|
|
|
|
}
|