bool Pdf::open(const QString& path) { char* name = path.toAscii().data(); fz_try(ctx) { xref = pdf_open_xref(ctx, name, 0); pdf_load_page_tree(xref); } fz_catch(ctx) { pdf_free_xref(xref); xref = 0; } return true; }
int main(int argc, char **argv) { fz_error error; char *infile; char *password = ""; int c, o; while ((c = fz_getopt(argc, argv, "p:r")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'r': dorgb++; break; default: usage(); break; } } if (fz_optind == argc) usage(); infile = argv[fz_optind++]; ctx = fz_context_init(&fz_alloc_default); if (ctx == NULL) die(fz_error_note(ctx, 1, "failed to initialise context")); error = pdf_open_xref(ctx, &xref, infile, password); if (error) die(fz_error_note(ctx, error, "cannot open input file '%s'", infile)); if (fz_optind == argc) { for (o = 0; o < xref->len; o++) showobject(o); } else { while (fz_optind < argc) { showobject(atoi(argv[fz_optind])); fz_optind++; } } pdf_free_xref(xref); fz_flush_warnings(ctx); fz_context_fin(ctx); return 0; }
int main(int argc, char **argv) { fz_error error; char *infile; char *outfile = "out.pdf"; char *password = ""; int c, num; int subset; while ((c = fz_getopt(argc, argv, "adgp:")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'g': dogarbage ++; break; case 'd': doexpand ++; break; case 'a': doascii ++; break; default: usage(); break; } } if (argc - fz_optind < 1) usage(); infile = argv[fz_optind++]; if (argc - fz_optind > 0 && (strstr(argv[fz_optind], ".pdf") || strstr(argv[fz_optind], ".PDF"))) { outfile = argv[fz_optind++]; } subset = 0; if (argc - fz_optind > 0) subset = 1; ctx = fz_context_init(&fz_alloc_default); if (ctx == NULL) die(fz_error_note(ctx, 1, "failed to initialise context")); error = pdf_open_xref(ctx, &xref, infile, password); if (error) die(fz_error_note(ctx, error, "cannot open input file '%s'", infile)); out = fopen(outfile, "wb"); if (!out) die(fz_error_make(ctx, "cannot open output file '%s'", outfile)); fprintf(out, "%%PDF-%d.%d\n", xref->version / 10, xref->version % 10); fprintf(out, "%%\316\274\341\277\246\n\n"); uselist = fz_calloc(ctx, xref->len + 1, sizeof(char)); ofslist = fz_calloc(ctx, xref->len + 1, sizeof(int)); genlist = fz_calloc(ctx, xref->len + 1, sizeof(int)); renumbermap = fz_calloc(ctx, xref->len + 1, sizeof(int)); for (num = 0; num < xref->len; num++) { uselist[num] = 0; ofslist[num] = 0; genlist[num] = 0; renumbermap[num] = num; } /* Make sure any objects hidden in compressed streams have been loaded */ preloadobjstms(); /* Only retain the specified subset of the pages */ if (subset) retainpages(argc, argv); /* Sweep & mark objects from the trailer */ if (dogarbage >= 1) sweepobj(xref->trailer); /* Coalesce and renumber duplicate objects */ if (dogarbage >= 3) removeduplicateobjs(); /* Compact xref by renumbering and removing unused objects */ if (dogarbage >= 2) compactxref(); /* Make renumbering affect all indirect references and update xref */ /* Do not renumber objects if encryption is in use, as the object * numbers are baked into the streams/strings, and we can't currently * cope with moving them. See bug 692627. */ if (dogarbage >= 2 && xref->crypt == NULL) renumberobjs(); writepdf(); if (fclose(out)) die(fz_error_make(ctx, "cannot close output file '%s'", outfile)); fz_free(xref->ctx, uselist); fz_free(xref->ctx, ofslist); fz_free(xref->ctx, genlist); fz_free(xref->ctx, renumbermap); pdf_free_xref(xref); fz_flush_warnings(ctx); fz_context_fin(ctx); return 0; }