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>
|
2009-09-27 14:39:04 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
2011-08-11 14:48:37 +00:00
|
|
|
#include <cstring>
|
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();
|
|
|
|
|
|
|
|
QPDF* qpdf;
|
|
|
|
QPDFWriter* qpdf_writer;
|
|
|
|
|
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;
|
|
|
|
Buffer* output_buffer;
|
2009-09-27 03:11:29 +00:00
|
|
|
};
|
|
|
|
|
2009-09-27 14:39:04 +00:00
|
|
|
_qpdf_data::_qpdf_data() :
|
|
|
|
qpdf(0),
|
2011-08-11 15:56:37 +00:00
|
|
|
qpdf_writer(0),
|
|
|
|
write_memory(false),
|
|
|
|
output_buffer(0)
|
2009-09-27 14:39:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
_qpdf_data::~_qpdf_data()
|
|
|
|
{
|
|
|
|
delete qpdf_writer;
|
|
|
|
delete qpdf;
|
2011-08-11 15:56:37 +00:00
|
|
|
delete output_buffer;
|
2009-09-27 14:39:04 +00:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
qpdf->size, qpdf->password);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2009-10-20 00:46:26 +00:00
|
|
|
static QPDF_ERROR_CODE trap_errors(qpdf_data qpdf, void (*fn)(qpdf_data))
|
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");
|
2009-09-27 03:11:29 +00:00
|
|
|
delete *qpdf;
|
|
|
|
*qpdf = 0;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2010-09-24 20:45:18 +00:00
|
|
|
return 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");
|
|
|
|
qpdf->qpdf->setSuppressWarnings(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_ignore_xref_streams(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_ignore_xref_streams");
|
|
|
|
qpdf->qpdf->setIgnoreXRefStreams(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_attempt_recovery(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_attempt_recovery");
|
|
|
|
qpdf->qpdf->setAttemptRecovery(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
return qpdf->qpdf->allowAccessibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_extract_all(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_extract_all");
|
|
|
|
return qpdf->qpdf->allowExtractAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_print_low_res(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_print_low_res");
|
|
|
|
return qpdf->qpdf->allowPrintLowRes();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_print_high_res(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_print_high_res");
|
|
|
|
return qpdf->qpdf->allowPrintHighRes();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_assembly(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_assembly");
|
|
|
|
return qpdf->qpdf->allowModifyAssembly();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_form(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_form");
|
|
|
|
return qpdf->qpdf->allowModifyForm();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_annotation(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_annotation");
|
|
|
|
return qpdf->qpdf->allowModifyAnnotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_other(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_other");
|
|
|
|
return qpdf->qpdf->allowModifyOther();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPDF_BOOL qpdf_allow_modify_all(qpdf_data qpdf)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_allow_modify_all");
|
|
|
|
return qpdf->qpdf->allowModifyAll();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-10-20 00:46:26 +00:00
|
|
|
if (qpdf->qpdf_writer)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");
|
|
|
|
delete qpdf->qpdf_writer;
|
|
|
|
qpdf->qpdf_writer = 0;
|
2011-08-11 15:56:37 +00:00
|
|
|
if (qpdf->output_buffer)
|
|
|
|
{
|
|
|
|
delete qpdf->output_buffer;
|
|
|
|
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;
|
2011-08-11 15:56:37 +00:00
|
|
|
if (qpdf->output_buffer)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (qpdf->output_buffer)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setCompressStreams(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setPreserveUnreferencedObjects(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_newline_before_endstream(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_newline_before_endstream");
|
|
|
|
qpdf->qpdf_writer->setNewlineBeforeEndstream(value);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setContentNormalization(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_qdf_mode(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_qdf_mode");
|
|
|
|
qpdf->qpdf_writer->setQDFMode(value);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setDeterministicID(value);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setStaticID(value);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setStaticAesIV(value);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setSuppressOriginalObjectIDs(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qpdf_set_preserve_encryption(qpdf_data qpdf, QPDF_BOOL value)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_preserve_encryption");
|
|
|
|
qpdf->qpdf_writer->setPreserveEncryption(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
allow_print, allow_modify, allow_extract, allow_annotate);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR3EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2009-10-19 20:17:14 +00:00
|
|
|
allow_accessibility, allow_extract, print, modify);
|
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
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR4EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
2009-10-19 20:17:14 +00:00
|
|
|
allow_accessibility, allow_extract, print, modify,
|
2009-10-19 00:36:51 +00:00
|
|
|
encrypt_metadata, use_aes);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR5EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
|
|
|
allow_accessibility, allow_extract, print, modify,
|
|
|
|
encrypt_metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
|
|
|
|
qpdf->qpdf_writer->setR6EncryptionParameters(
|
|
|
|
user_password, owner_password,
|
|
|
|
allow_accessibility, allow_extract, print, modify,
|
|
|
|
encrypt_metadata);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
qpdf->qpdf_writer->setLinearization(value);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|