| 1 |
|
| 2 |
#include <stdio.h> |
| 3 |
#include "ppapi.h" |
| 4 |
#include "util/utiliof.h" |
| 5 |
|
| 6 |
static const char * sizenum (size_t s) |
| 7 |
{ |
| 8 |
static char buffer[32]; |
| 9 |
if (s < 1000) |
| 10 |
sprintf(buffer, "%uB", (unsigned)s); |
| 11 |
else if (s < 1000000) |
| 12 |
sprintf(buffer, "%.2fkB", (double)(s) / 1000); |
| 13 |
else |
| 14 |
sprintf(buffer, "%.2fMB", (double)(s) / 1000000); |
| 15 |
return buffer; |
| 16 |
} |
| 17 |
|
| 18 |
static const char * crypt_info (ppdoc *pdf) |
| 19 |
{ |
| 20 |
switch (ppdoc_crypt_status(pdf)) |
| 21 |
{ |
| 22 |
case PPCRYPT_NONE: |
| 23 |
return "none"; |
| 24 |
case PPCRYPT_DONE: |
| 25 |
return "empty password"; |
| 26 |
case PPCRYPT_PASS: |
| 27 |
return "nonempty password"; |
| 28 |
default: |
| 29 |
break; |
| 30 |
} |
| 31 |
return "this shouldn't happen"; |
| 32 |
} |
| 33 |
|
| 34 |
static void print_info (ppdoc *pdf) |
| 35 |
{ |
| 36 |
ppdict *info; |
| 37 |
ppstring *creator, *producer; |
| 38 |
size_t memused, memwaste; |
| 39 |
|
| 40 |
if ((info = ppdoc_info(pdf)) != NULL) |
| 41 |
{ |
| 42 |
if ((creator = ppdict_rget_string(info, "Creator")) != NULL) |
| 43 |
printf(" creator: %s\n", ppstring_decoded_data(creator)); |
| 44 |
if ((producer = ppdict_rget_string(info, "Producer")) != NULL) |
| 45 |
printf(" producer: %s\n", ppstring_decoded_data(producer)); |
| 46 |
} |
| 47 |
printf(" version: %s\n", ppdoc_version_string(pdf)); |
| 48 |
printf(" protection: %s\n", crypt_info(pdf)); |
| 49 |
printf(" filesize: %s\n", sizenum(ppdoc_file_size(pdf))); |
| 50 |
printf(" objects: %lu\n", (unsigned long)ppdoc_objects(pdf)); |
| 51 |
printf(" pagecount: %lu\n", (unsigned long)ppdoc_page_count(pdf)); |
| 52 |
memused = ppdoc_memory(pdf, &memwaste); |
| 53 |
printf(" memused: %s\n", sizenum(memused)); |
| 54 |
printf(" memwaste: %s\n", sizenum(memwaste)); |
| 55 |
} |
| 56 |
|
| 57 |
static int usage (const char *argv0) |
| 58 |
{ |
| 59 |
printf("pplib " pplib_version ", " pplib_author "\n"); |
| 60 |
printf("usage: %s file1.pdf file2.pdf ...\n", argv0); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
int main (int argc, const char **argv) |
| 65 |
{ |
| 66 |
const char *filepath; |
| 67 |
int a; |
| 68 |
ppdoc *pdf; |
| 69 |
const void *data; |
| 70 |
size_t size; |
| 71 |
|
| 72 |
if (argc < 2) |
| 73 |
return usage(argv[0]); |
| 74 |
for (a = 1; a < argc; ++a) |
| 75 |
{ |
| 76 |
filepath = argv[a]; |
| 77 |
printf("loading %s... ", filepath); |
| 78 |
pdf = ppdoc_load(filepath); |
| 79 |
if (pdf == NULL) |
| 80 |
{ |
| 81 |
printf("failed\n"); |
| 82 |
continue; |
| 83 |
} |
| 84 |
printf("done.\n"); |
| 85 |
print_info(pdf); |
| 86 |
ppdoc_free(pdf); |
| 87 |
/* now loading from memory buffer */ |
| 88 |
printf("loading %s from mem buffer... ", filepath); |
| 89 |
data = iof_copy_file_data(filepath, &size); |
| 90 |
if (data != NULL) |
| 91 |
{ |
| 92 |
pdf = ppdoc_mem(data, size); |
| 93 |
if (pdf == NULL) |
| 94 |
{ |
| 95 |
printf("failed\n"); |
| 96 |
continue; |
| 97 |
} |
| 98 |
printf("done.\n"); |
| 99 |
//print_info(pdf); |
| 100 |
ppdoc_free(pdf); |
| 101 |
} |
| 102 |
} |
| 103 |
return 0; |
| 104 |
} |