summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/tools/pdfextract.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c
index 65bfb496..6d901d72 100644
--- a/source/tools/pdfextract.c
+++ b/source/tools/pdfextract.c
@@ -83,17 +83,14 @@ writejpeg(fz_context *ctx, const unsigned char *data, size_t len, const char *fi
fz_rethrow(ctx);
}
-static void saveimage(int num)
+static void saveimage(pdf_obj *ref)
{
fz_image *image = NULL;
fz_pixmap *pix = NULL;
- pdf_obj *ref;
char buf[32];
fz_compressed_buffer *cbuf;
int type;
- ref = pdf_new_indirect(ctx, doc, num, 0);
-
fz_var(image);
fz_var(pix);
@@ -101,7 +98,7 @@ static void saveimage(int num)
{
image = pdf_load_image(ctx, doc, ref);
cbuf = fz_compressed_image_buffer(ctx, image);
- fz_snprintf(buf, sizeof(buf), "img-%04d", num);
+ fz_snprintf(buf, sizeof(buf), "img-%04d", pdf_to_num(ctx, ref));
type = cbuf == NULL ? FZ_IMAGE_UNKNOWN : cbuf->params.type;
if (image->use_colorkey)
@@ -140,7 +137,7 @@ static void saveimage(int num)
fz_rethrow(ctx);
}
-static void savefont(pdf_obj *dict, int num)
+static void savefont(pdf_obj *dict)
{
char namebuf[1024];
fz_buffer *buf;
@@ -199,7 +196,7 @@ static void savefont(pdf_obj *dict, int num)
len = fz_buffer_storage(ctx, buf, &data);
fz_try(ctx)
{
- fz_snprintf(namebuf, sizeof(namebuf), "%s-%04d.%s", fontname, num, ext);
+ fz_snprintf(namebuf, sizeof(namebuf), "%s-%04d.%s", fontname, pdf_to_num(ctx, dict), ext);
printf("extracting font %s\n", namebuf);
out = fz_new_output_with_path(ctx, namebuf, 0);
fz_try(ctx)
@@ -218,23 +215,23 @@ static void savefont(pdf_obj *dict, int num)
fz_rethrow(ctx);
}
-static void showobject(int num)
+static void extractobject(int num)
{
- pdf_obj *obj;
+ pdf_obj *ref;
if (!doc)
fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified");
fz_try(ctx)
{
- obj = pdf_load_object(ctx, doc, num);
+ ref = pdf_new_indirect(ctx, doc, num, 0);
- if (isimage(obj))
- saveimage(num);
- else if (isfontdesc(obj))
- savefont(obj, num);
+ if (isimage(ref))
+ saveimage(ref);
+ if (isfontdesc(ref))
+ savefont(ref);
- pdf_drop_obj(ctx, obj);
+ pdf_drop_obj(ctx, ref);
}
fz_catch(ctx)
{
@@ -279,13 +276,13 @@ int pdfextract_main(int argc, char **argv)
{
int len = pdf_count_objects(ctx, doc);
for (o = 1; o < len; o++)
- showobject(o);
+ extractobject(o);
}
else
{
while (fz_optind < argc)
{
- showobject(atoi(argv[fz_optind]));
+ extractobject(atoi(argv[fz_optind]));
fz_optind++;
}
}