aboutsummaryrefslogtreecommitdiffstats
path: root/src/pdf_writer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf_writer.c')
-rw-r--r--src/pdf_writer.c37
1 files changed, 25 insertions, 12 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(&timestamp));
+ 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);