2009-09-27 20:59:16 +00:00
|
|
|
/*
|
|
|
|
* This is an example program to linearize a PDF file using the C API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qpdf/qpdf-c.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static char const* whoami = 0;
|
|
|
|
|
|
|
|
static void usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s infile infile-password outfile\n", whoami);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
char* infile = argv[1];
|
|
|
|
char* password = argv[2];
|
|
|
|
char* outfile = argv[3];
|
|
|
|
qpdf_data qpdf = qpdf_init();
|
|
|
|
int warnings = 0;
|
|
|
|
int errors = 0;
|
|
|
|
char* p = 0;
|
2009-10-20 00:24:44 +00:00
|
|
|
qpdf_error e = 0;
|
2009-09-27 20:59:16 +00:00
|
|
|
|
|
|
|
if ((p = strrchr(argv[0], '/')) != NULL)
|
|
|
|
{
|
|
|
|
whoami = p + 1;
|
|
|
|
}
|
|
|
|
else if ((p = strrchr(argv[0], '\\')) != NULL)
|
|
|
|
{
|
|
|
|
whoami = p + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
whoami = argv[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
|
|
|
|
((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))
|
|
|
|
{
|
|
|
|
qpdf_set_static_ID(qpdf, QPDF_TRUE);
|
|
|
|
qpdf_set_linearization(qpdf, QPDF_TRUE);
|
|
|
|
qpdf_write(qpdf);
|
|
|
|
}
|
|
|
|
while (qpdf_more_warnings(qpdf))
|
|
|
|
{
|
|
|
|
warnings = 1;
|
2009-10-20 00:24:44 +00:00
|
|
|
printf("warning: %s\n",
|
|
|
|
qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
|
2009-09-27 20:59:16 +00:00
|
|
|
}
|
2009-10-20 00:24:44 +00:00
|
|
|
e = qpdf_get_error(qpdf);
|
|
|
|
if (e)
|
2009-09-27 20:59:16 +00:00
|
|
|
{
|
|
|
|
errors = 1;
|
2009-10-20 00:24:44 +00:00
|
|
|
printf("error: %s\n", qpdf_get_error_full_text(qpdf, e));
|
2009-09-27 20:59:16 +00:00
|
|
|
}
|
|
|
|
qpdf_cleanup(&qpdf);
|
|
|
|
if (errors)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (warnings)
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|