static void expandstream(fz_obj *obj, int num, int gen) { fz_buffer *buf, *tmp; fz_obj *newlen; buf = pdf_load_stream(xref, num, gen); fz_dict_dels(obj, "Filter"); fz_dict_dels(obj, "DecodeParms"); if (doascii && isbinarystream(buf)) { tmp = hexbuf(buf->data, buf->len); fz_drop_buffer(ctx, buf); buf = tmp; addhexfilter(obj); } newlen = fz_new_int(ctx, buf->len); fz_dict_puts(obj, "Length", newlen); fz_drop_obj(newlen); fprintf(out, "%d %d obj\n", num, gen); fz_fprint_obj(out, obj, doexpand == 0); fprintf(out, "stream\n"); fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); fz_drop_buffer(ctx, buf); }
static void copystream(fz_obj *obj, int num, int gen) { fz_error error; fz_buffer *buf, *tmp; fz_obj *newlen; error = pdf_load_raw_stream(&buf, xref, num, gen); if (error) die(error); if (doascii && isbinarystream(buf)) { tmp = hexbuf(buf->data, buf->len); fz_drop_buffer(ctx, buf); buf = tmp; addhexfilter(obj); newlen = fz_new_int(ctx, buf->len); fz_dict_puts(ctx, obj, "Length", newlen); fz_drop_obj(ctx, newlen); } fprintf(out, "%d %d obj\n", num, gen); fz_fprint_obj(ctx, out, obj, !doexpand); fprintf(out, "stream\n"); fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); fz_drop_buffer(ctx, buf); }
static void writexref(void) { fz_obj *trailer; fz_obj *obj; int startxref; int num; startxref = ftell(out); fprintf(out, "xref\n0 %d\n", xref->len); for (num = 0; num < xref->len; num++) { if (uselist[num]) fprintf(out, "%010d %05d n \n", ofslist[num], genlist[num]); else fprintf(out, "%010d %05d f \n", ofslist[num], genlist[num]); } fprintf(out, "\n"); trailer = fz_new_dict(ctx, 5); obj = fz_new_int(ctx, xref->len); fz_dict_puts(trailer, "Size", obj); fz_drop_obj(obj); obj = fz_dict_gets(xref->trailer, "Info"); if (obj) fz_dict_puts(trailer, "Info", obj); obj = fz_dict_gets(xref->trailer, "Root"); if (obj) fz_dict_puts(trailer, "Root", obj); obj = fz_dict_gets(xref->trailer, "ID"); if (obj) fz_dict_puts(trailer, "ID", obj); fprintf(out, "trailer\n"); fz_fprint_obj(out, trailer, doexpand == 0); fprintf(out, "\n"); fz_drop_obj(trailer); fprintf(out, "startxref\n%d\n%%%%EOF\n", startxref); }
static void writeobject(int num, int gen) { fz_error error; fz_obj *obj; fz_obj *type; error = pdf_load_object(&obj, xref, num, gen); if (error) die(error); /* skip ObjStm and XRef objects */ if (fz_is_dict(ctx, obj)) { type = fz_dict_gets(ctx, obj, "Type"); if (fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "ObjStm")) { uselist[num] = 0; fz_drop_obj(ctx, obj); return; } if (fz_is_name(ctx, type) && !strcmp(fz_to_name(ctx, type), "XRef")) { uselist[num] = 0; fz_drop_obj(ctx, obj); return; } } if (!pdf_is_stream(xref, num, gen)) { fprintf(out, "%d %d obj\n", num, gen); fz_fprint_obj(ctx, out, obj, !doexpand); fprintf(out, "endobj\n\n"); } else { if (doexpand && !pdf_is_jpx_image(ctx, obj)) expandstream(obj, num, gen); else copystream(obj, num, gen); } fz_drop_obj(ctx, obj); }
static void writeobject(int num, int gen) { fz_obj *obj; fz_obj *type; obj = pdf_load_object(xref, num, gen); /* skip ObjStm and XRef objects */ if (fz_is_dict(obj)) { type = fz_dict_gets(obj, "Type"); if (fz_is_name(type) && !strcmp(fz_to_name(type), "ObjStm")) { uselist[num] = 0; fz_drop_obj(obj); return; } if (fz_is_name(type) && !strcmp(fz_to_name(type), "XRef")) { uselist[num] = 0; fz_drop_obj(obj); return; } } if (!pdf_is_stream(xref, num, gen)) { fprintf(out, "%d %d obj\n", num, gen); fz_fprint_obj(out, obj, doexpand == 0); fprintf(out, "endobj\n\n"); } else { int dontexpand = 0; if (doexpand != 0 && doexpand != expand_all) { fz_obj *o; if ((o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "XObject")) && (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Image"))) dontexpand = !(doexpand & expand_images); if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "Font")) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Type"), !strcmp(fz_to_name(o), "FontDescriptor")) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length1")) != NULL) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length2")) != NULL) dontexpand = !(doexpand & expand_fonts); if ((o = fz_dict_gets(obj, "Length3")) != NULL) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "Type1C")) dontexpand = !(doexpand & expand_fonts); if (o = fz_dict_gets(obj, "Subtype"), !strcmp(fz_to_name(o), "CIDFontType0C")) dontexpand = !(doexpand & expand_fonts); } if (doexpand && !dontexpand && !pdf_is_jpx_image(ctx, obj)) expandstream(obj, num, gen); else copystream(obj, num, gen); } fz_drop_obj(obj); }