diff options
author | yzrh <yzrh@noema.org> | 2023-01-05 19:13:37 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2023-01-05 19:15:01 +0000 |
commit | 123d62141cce0cbeb2ae6eb80b669af7db1c8c72 (patch) | |
tree | 09094e1d3ca23ee96b842f6a697b87eb1497d61b | |
parent | 283446dba5ce6e1a61b46377999a45f0b85a6937 (diff) | |
download | melon-123d62141cce0cbeb2ae6eb80b669af7db1c8c72.tar.gz melon-123d62141cce0cbeb2ae6eb80b669af7db1c8c72.tar.zst |
Add document information dictionary to output.
Signed-off-by: yzrh <yzrh@noema.org>
-rw-r--r-- | src/pdf_writer.c | 37 | ||||
-rw-r--r-- | src/version.h | 4 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/pdf_writer.c b/src/pdf_writer.c index 465d26b..6afa89b 100644 --- a/src/pdf_writer.c +++ b/src/pdf_writer.c @@ -1,19 +1,39 @@ /* - * Copyright (c) 2020-2022, yzrh <yzrh@noema.org> + * Copyright (c) 2020-2023, yzrh <yzrh@noema.org> * * SPDX-License-Identifier: Apache-2.0 */ #include <stdlib.h> +#include <string.h> #include <time.h> +#include "version.h" #include "md5.h" #include "pdf.h" +static int +_info_obj(pdf_object_t **pdf) +{ + char dictionary[128] = "<<\n" + "/Producer (Melon " VERSION "." RELEASE "." PATCH EXTRA ")\n" + "/CreationDate (D:"; + + char buf[64]; + + time_t timestamp = time(NULL); + + strftime(buf, 64, "%Y%m%d%H%M%S", gmtime(×tamp)); + strcat(dictionary, buf); + strcat(dictionary, "+00'00')\n>>"); + + return pdf_obj_append(pdf, 0, NULL, dictionary, NULL, 0); +} + int pdf_dump_obj(pdf_object_t **pdf, FILE **fp) { - if (*pdf == NULL || *fp == NULL) + if (*pdf == NULL || *fp == NULL || _info_obj(pdf) != 0) return 1; long cur; @@ -152,18 +172,11 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref) while (ptr->next != NULL) ptr = ptr->next; - /* - * TODO: Document information dictionary - * `"/Producer (Melon)"' - * `"/CreationDate (D:YYYYMMDDHHmmSS+00'00')"' - * - * Trailer dictionary - * `"/Info %d 0 R"' - */ fprintf(*fp, - "/Size %d\n/Root %d 0 R\n", + "/Size %d\n/Root %d 0 R\n/Info %d 0 R\n", ptr->id + 1, - pdf_get_catalog_id(pdf)); + pdf_get_catalog_id(pdf), + ptr->id); fputs("/ID [", *fp); diff --git a/src/version.h b/src/version.h index 46eeb34..c3ff314 100644 --- a/src/version.h +++ b/src/version.h @@ -5,6 +5,6 @@ */ #define VERSION "0" -#define RELEASE "2" -#define PATCH "5" +#define RELEASE "3" +#define PATCH "0" #define EXTRA "" |