1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
#include <qpdf/qpdf-c.h>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFWriter.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QPDFExc.hh>
#include <qpdf/Pl_Discard.hh>
#include <list>
#include <string>
#include <stdexcept>
#include <cstring>
struct _qpdf_error
{
PointerHolder<QPDFExc> exc;
};
struct _qpdf_data
{
_qpdf_data();
~_qpdf_data();
QPDF* qpdf;
QPDFWriter* qpdf_writer;
PointerHolder<QPDFExc> error;
_qpdf_error tmp_error;
std::list<QPDFExc> warnings;
std::string tmp_string;
// Parameters for functions we call
char const* filename; // or description
char const* buffer;
unsigned long long size;
char const* password;
bool write_memory;
Buffer* output_buffer;
};
_qpdf_data::_qpdf_data() :
qpdf(0),
qpdf_writer(0),
write_memory(false),
output_buffer(0)
{
}
_qpdf_data::~_qpdf_data()
{
delete qpdf_writer;
delete qpdf;
delete output_buffer;
}
// must set qpdf->filename and qpdf->password
static void call_read(qpdf_data qpdf)
{
qpdf->qpdf->processFile(qpdf->filename, qpdf->password);
}
// 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);
}
// must set qpdf->filename
static void call_init_write(qpdf_data qpdf)
{
qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf), qpdf->filename);
}
static void call_init_write_memory(qpdf_data qpdf)
{
qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf));
qpdf->qpdf_writer->setOutputMemory();
}
static void call_write(qpdf_data qpdf)
{
qpdf->qpdf_writer->write();
}
static void call_check(qpdf_data qpdf)
{
QPDFWriter w(*qpdf->qpdf);
Pl_Discard discard;
w.setOutputPipeline(&discard);
w.setDecodeLevel(qpdf_dl_all);
w.write();
}
static QPDF_ERROR_CODE trap_errors(qpdf_data qpdf, void (*fn)(qpdf_data))
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
try
{
fn(qpdf);
}
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());
status |= QPDF_ERRORS;
}
catch (std::exception& e)
{
qpdf->error = new QPDFExc(qpdf_e_internal, "", "", 0, e.what());
status |= QPDF_ERRORS;
}
if (qpdf_more_warnings(qpdf))
{
status |= QPDF_WARNINGS;
}
return status;
}
char const* qpdf_get_qpdf_version()
{
QTC::TC("qpdf", "qpdf-c called qpdf_get_qpdf_version");
return QPDF::QPDFVersion().c_str();
}
qpdf_data qpdf_init()
{
QTC::TC("qpdf", "qpdf-c called qpdf_init");
qpdf_data qpdf = new _qpdf_data();
qpdf->qpdf = new QPDF();
return qpdf;
}
void qpdf_cleanup(qpdf_data* qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_cleanup");
delete *qpdf;
*qpdf = 0;
}
QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_more_warnings");
if (qpdf->warnings.empty())
{
std::vector<QPDFExc> w = qpdf->qpdf->getWarnings();
if (! w.empty())
{
qpdf->warnings.assign(w.begin(), w.end());
}
}
if (qpdf->warnings.empty())
{
return QPDF_FALSE;
}
else
{
return QPDF_TRUE;
}
}
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);
}
qpdf_error qpdf_get_error(qpdf_data qpdf)
{
if (qpdf->error.getPointer())
{
qpdf->tmp_error.exc = qpdf->error;
qpdf->error = 0;
QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error");
return &qpdf->tmp_error;
}
else
{
return 0;
}
}
qpdf_error qpdf_next_warning(qpdf_data qpdf)
{
if (qpdf_more_warnings(qpdf))
{
qpdf->tmp_error.exc = new QPDFExc(qpdf->warnings.front());
qpdf->warnings.pop_front();
QTC::TC("qpdf", "qpdf-c qpdf_next_warning returned warning");
return &qpdf->tmp_error;
}
else
{
return 0;
}
}
char const* qpdf_get_error_full_text(qpdf_data qpdf, qpdf_error e)
{
if (e == 0)
{
return "";
}
return e->exc->what();
}
enum qpdf_error_code_e qpdf_get_error_code(qpdf_data qpdf, qpdf_error e)
{
if (e == 0)
{
return qpdf_e_success;
}
return e->exc->getErrorCode();
}
char const* qpdf_get_error_filename(qpdf_data qpdf, qpdf_error e)
{
if (e == 0)
{
return "";
}
return e->exc->getFilename().c_str();
}
unsigned long long qpdf_get_error_file_position(qpdf_data qpdf, qpdf_error e)
{
if (e == 0)
{
return 0;
}
return e->exc->getFilePosition();
}
char const* qpdf_get_error_message_detail(qpdf_data qpdf, qpdf_error e)
{
if (e == 0)
{
return "";
}
return e->exc->getMessageDetail().c_str();
}
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;
}
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;
qpdf->filename = filename;
qpdf->password = password;
status = trap_errors(qpdf, &call_read);
// 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
);
return status;
}
QPDF_ERROR_CODE qpdf_read_memory(qpdf_data qpdf,
char const* description,
char const* buffer,
unsigned long long size,
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;
}
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();
}
int qpdf_get_pdf_extension_level(qpdf_data qpdf)
{
QTC::TC("qpdf", "qpdf-c called qpdf_get_pdf_extension_level");
return qpdf->qpdf->getExtensionLevel();
}
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();
}
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",
qpdf->qpdf->makeIndirectObject(QPDFObjectHandle::newDictionary()));
}
else
{
QTC::TC("qpdf", "qpdf-c set-info-key use existing info");
}
QPDFObjectHandle info = trailer.getKey("/Info");
info.replaceOrRemoveKey(key, value_object);
}
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);
}
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();
}
static void qpdf_init_write_internal(qpdf_data qpdf)
{
if (qpdf->qpdf_writer)
{
QTC::TC("qpdf", "qpdf-c called qpdf_init_write multiple times");
delete qpdf->qpdf_writer;
qpdf->qpdf_writer = 0;
if (qpdf->output_buffer)
{
delete qpdf->output_buffer;
qpdf->output_buffer = 0;
qpdf->write_memory = false;
qpdf->filename = 0;
}
}
}
QPDF_ERROR_CODE qpdf_init_write(qpdf_data qpdf, char const* filename)
{
qpdf_init_write_internal(qpdf);
qpdf->filename = filename;
QPDF_ERROR_CODE status = trap_errors(qpdf, &call_init_write);
QTC::TC("qpdf", "qpdf-c called qpdf_init_write", status);
return status;
}
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();
}
}
size_t qpdf_get_buffer_length(qpdf_data qpdf)
{
qpdf_get_buffer_internal(qpdf);
size_t result = 0;
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;
}
void qpdf_set_object_stream_mode(qpdf_data qpdf, qpdf_object_stream_e mode)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_object_stream_mode");
qpdf->qpdf_writer->setObjectStreamMode(mode);
}
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);
}
void qpdf_set_stream_data_mode(qpdf_data qpdf, qpdf_stream_data_e mode)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_stream_data_mode");
qpdf->qpdf_writer->setStreamDataMode(mode);
}
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);
}
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);
}
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);
}
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);
}
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_parameters2(
qpdf_data qpdf, char const* user_password, char const* owner_password,
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
enum qpdf_r3_print_e print)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters");
qpdf->qpdf_writer->setR3EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract,
allow_assemble, allow_annotate_and_form,
allow_form_filling, allow_modify_other,
print);
}
void qpdf_set_r4_encryption_parameters2(
qpdf_data qpdf, char const* user_password, char const* owner_password,
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
enum qpdf_r3_print_e print,
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters");
qpdf->qpdf_writer->setR4EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract,
allow_assemble, allow_annotate_and_form,
allow_form_filling, allow_modify_other,
print, encrypt_metadata, use_aes);
}
void qpdf_set_r5_encryption_parameters2(
qpdf_data qpdf, char const* user_password, char const* owner_password,
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
qpdf->qpdf_writer->setR5EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract,
allow_assemble, allow_annotate_and_form,
allow_form_filling, allow_modify_other,
print, encrypt_metadata);
}
void qpdf_set_r6_encryption_parameters2(
qpdf_data qpdf, char const* user_password, char const* owner_password,
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
qpdf->qpdf_writer->setR6EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract,
allow_assemble, allow_annotate_and_form,
allow_form_filling, allow_modify_other,
print, encrypt_metadata);
}
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,
qpdf_r3_print_e print, qpdf_r3_modify_e modify)
{
qpdf->qpdf_writer->setR3EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract, print, modify);
}
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,
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
{
qpdf->qpdf_writer->setR4EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract, print, modify,
encrypt_metadata, use_aes);
}
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)
{
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)
{
qpdf->qpdf_writer->setR6EncryptionParameters(
user_password, owner_password,
allow_accessibility, allow_extract, print, modify,
encrypt_metadata);
}
void qpdf_set_linearization(qpdf_data qpdf, QPDF_BOOL value)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_linearization");
qpdf->qpdf_writer->setLinearization(value);
}
void qpdf_set_minimum_pdf_version(qpdf_data qpdf, char const* version)
{
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)
{
QTC::TC("qpdf", "qpdf-c called qpdf_set_minimum_pdf_version");
qpdf->qpdf_writer->setMinimumPDFVersion(version, extension_level);
}
void qpdf_force_pdf_version(qpdf_data qpdf, char const* version)
{
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)
{
QTC::TC("qpdf", "qpdf-c called qpdf_force_pdf_version");
qpdf->qpdf_writer->forcePDFVersion(version, extension_level);
}
QPDF_ERROR_CODE qpdf_write(qpdf_data qpdf)
{
QPDF_ERROR_CODE status = QPDF_SUCCESS;
status = trap_errors(qpdf, &call_write);
QTC::TC("qpdf", "qpdf-c called qpdf_write", (status == 0) ? 0 : 1);
return status;
}
|