From 9d7e833e33e37e0be20b82a9153d18f5148e94d5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 23 Dec 2016 14:24:29 +0100 Subject: Cope with NULL resource and concents arguments to pdf_add_page. --- source/pdf/pdf-page.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source/pdf/pdf-page.c') diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 64b30cf6..1b20b091 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -683,8 +683,16 @@ pdf_add_page(fz_context *ctx, pdf_document *doc, const fz_rect *mediabox, int ro pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Type, PDF_NAME_Page); pdf_dict_put_drop(ctx, page_obj, PDF_NAME_MediaBox, pdf_new_rect(ctx, doc, mediabox)); pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Rotate, pdf_new_int(ctx, doc, rotate)); - pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Resources, pdf_add_object(ctx, doc, resources)); - pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Contents, pdf_add_stream(ctx, doc, contents, NULL, 0)); + + if (pdf_is_indirect(ctx, resources)) + pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Resources, resources); + else if (pdf_is_dict(ctx, resources)) + pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Resources, pdf_add_object(ctx, doc, resources)); + else + pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Resources, pdf_new_dict(ctx, doc, 1)); + + if (contents) + pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Contents, pdf_add_stream(ctx, doc, contents, NULL, 0)); } fz_catch(ctx) { -- cgit v1.2.3