2022-02-01 14:58:32 +00:00
|
|
|
/*
|
|
|
|
* This is an example program to linearize a PDF file using the C
|
|
|
|
* QPDFJob API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qpdf/qpdfjob-c.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static char const* whoami = 0;
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
static void
|
|
|
|
usage()
|
2022-02-01 14:58:32 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s infile outfile\n", whoami);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2022-02-01 14:58:32 +00:00
|
|
|
{
|
|
|
|
char* infile = NULL;
|
|
|
|
char* outfile = NULL;
|
|
|
|
char const* new_argv[6];
|
|
|
|
int r = 0;
|
|
|
|
char* p = 0;
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((p = strrchr(argv[0], '/')) != NULL) {
|
2022-02-08 14:18:08 +00:00
|
|
|
whoami = p + 1;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else if ((p = strrchr(argv[0], '\\')) != NULL) {
|
2022-02-08 14:18:08 +00:00
|
|
|
whoami = p + 1;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2022-02-08 14:18:08 +00:00
|
|
|
whoami = argv[0];
|
2022-02-01 14:58:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (argc != 3) {
|
2022-02-08 14:18:08 +00:00
|
|
|
usage();
|
2022-02-01 14:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
infile = argv[1];
|
|
|
|
outfile = argv[2];
|
|
|
|
|
|
|
|
new_argv[0] = "qpdfjob";
|
|
|
|
new_argv[1] = infile;
|
|
|
|
new_argv[2] = outfile;
|
|
|
|
new_argv[3] = "--linearize";
|
|
|
|
new_argv[4] = "--static-id"; /* for testing only */
|
|
|
|
new_argv[5] = NULL;
|
|
|
|
|
|
|
|
/* See qpdf-job.cc for a C++ example of using the json interface.
|
|
|
|
* To use that from C just like the argv one, call
|
|
|
|
* qpdfjob_run_from_json instead and pass the json string as a
|
|
|
|
* single char const* argument.
|
2022-06-18 18:16:56 +00:00
|
|
|
*
|
|
|
|
* See qpdfjob-c-save-attachment.c for an example of using the
|
|
|
|
* full form of the qpdfjob interface with init and cleanup
|
|
|
|
* functions.
|
2022-02-01 14:58:32 +00:00
|
|
|
*/
|
2022-02-01 18:49:11 +00:00
|
|
|
r = qpdfjob_run_from_argv(new_argv);
|
2022-02-01 14:58:32 +00:00
|
|
|
return r;
|
|
|
|
}
|