File Coverage

include/pdfmake_meta.h
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             /*
2             * pdfmake_meta.h — Document Information Dictionary (§14.3.3).
3             *
4             * Provides functions to set and get standard metadata fields like
5             * Title, Author, Subject, Keywords, Creator, Producer, CreationDate,
6             * ModDate, and Trapped.
7             *
8             * PDF date format (§7.9.4): D:YYYYMMDDHHmmSSOHH'mm'
9             * - YYYY = year, MM = month (01-12), DD = day (01-31)
10             * - HH = hour (00-23), mm = minute (00-59), SS = second (00-59)
11             * - O = timezone relation (+, -, Z)
12             * - HH'mm' = timezone offset hours and minutes
13             */
14              
15             #ifndef PDFMAKE_META_H
16             #define PDFMAKE_META_H
17              
18             #include "pdfmake_types.h"
19             #include "pdfmake_doc.h"
20             #include
21              
22             #ifdef __cplusplus
23             extern "C" {
24             #endif
25              
26             /*----------------------------------------------------------------------------
27             * Standard metadata keys (§14.3.3)
28             *--------------------------------------------------------------------------*/
29              
30             #define PDFMAKE_META_TITLE "Title"
31             #define PDFMAKE_META_AUTHOR "Author"
32             #define PDFMAKE_META_SUBJECT "Subject"
33             #define PDFMAKE_META_KEYWORDS "Keywords"
34             #define PDFMAKE_META_CREATOR "Creator"
35             #define PDFMAKE_META_PRODUCER "Producer"
36             #define PDFMAKE_META_CREATION_DATE "CreationDate"
37             #define PDFMAKE_META_MOD_DATE "ModDate"
38             #define PDFMAKE_META_TRAPPED "Trapped"
39              
40             /*----------------------------------------------------------------------------
41             * PDF date formatting (§7.9.4)
42             *--------------------------------------------------------------------------*/
43              
44             /*
45             * Format a time_t as a PDF date string: D:YYYYMMDDHHmmSSOHH'mm'
46             * Uses local timezone. Buffer must be at least 24 bytes.
47             * Returns pointer to buf on success, NULL on error.
48             */
49             char *pdfmake_format_date(time_t t, char *buf, size_t buflen);
50              
51             /*
52             * Format a time_t as a PDF date string in UTC: D:YYYYMMDDHHMMSSZ
53             * Buffer must be at least 18 bytes.
54             * Returns pointer to buf on success, NULL on error.
55             */
56             char *pdfmake_format_date_utc(time_t t, char *buf, size_t buflen);
57              
58             /*----------------------------------------------------------------------------
59             * Generic metadata set/get
60             *--------------------------------------------------------------------------*/
61              
62             /*
63             * Set a metadata field on the document's /Info dictionary.
64             * Creates the /Info dictionary if it doesn't exist.
65             * Key should be one of the standard keys (Title, Author, etc.).
66             * Value is a string; dates should use pdfmake_format_date().
67             * Returns PDFMAKE_OK on success.
68             */
69             pdfmake_err_t pdfmake_meta_set(pdfmake_doc_t *doc, const char *key, const char *value);
70              
71             /*
72             * Get a metadata field from the document's /Info dictionary.
73             * Returns the string value, or NULL if not set or key not found.
74             * The returned string is owned by the document and must not be freed.
75             */
76             const char *pdfmake_meta_get(pdfmake_doc_t *doc, const char *key);
77              
78             /*----------------------------------------------------------------------------
79             * Convenience setters (string fields)
80             *--------------------------------------------------------------------------*/
81              
82 67           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_title(pdfmake_doc_t *doc, const char *v) {
83 67           return pdfmake_meta_set(doc, PDFMAKE_META_TITLE, v);
84             }
85              
86 57           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_author(pdfmake_doc_t *doc, const char *v) {
87 57           return pdfmake_meta_set(doc, PDFMAKE_META_AUTHOR, v);
88             }
89              
90 47           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_subject(pdfmake_doc_t *doc, const char *v) {
91 47           return pdfmake_meta_set(doc, PDFMAKE_META_SUBJECT, v);
92             }
93              
94 4           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_keywords(pdfmake_doc_t *doc, const char *v) {
95 4           return pdfmake_meta_set(doc, PDFMAKE_META_KEYWORDS, v);
96             }
97              
98 3           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_creator(pdfmake_doc_t *doc, const char *v) {
99 3           return pdfmake_meta_set(doc, PDFMAKE_META_CREATOR, v);
100             }
101              
102 4           static PDFMAKE_INLINE pdfmake_err_t pdfmake_meta_set_producer(pdfmake_doc_t *doc, const char *v) {
103 4           return pdfmake_meta_set(doc, PDFMAKE_META_PRODUCER, v);
104             }
105              
106             /*----------------------------------------------------------------------------
107             * Convenience setters (date fields)
108             *--------------------------------------------------------------------------*/
109              
110             /*
111             * Set CreationDate from a time_t value.
112             * Formats as PDF date string with local timezone.
113             */
114             pdfmake_err_t pdfmake_meta_set_creation_date(pdfmake_doc_t *doc, time_t t);
115              
116             /*
117             * Set ModDate from a time_t value.
118             * Formats as PDF date string with local timezone.
119             */
120             pdfmake_err_t pdfmake_meta_set_mod_date(pdfmake_doc_t *doc, time_t t);
121              
122             /*----------------------------------------------------------------------------
123             * Convenience getters
124             *--------------------------------------------------------------------------*/
125              
126 49           static PDFMAKE_INLINE const char *pdfmake_meta_get_title(pdfmake_doc_t *doc) {
127 49           return pdfmake_meta_get(doc, PDFMAKE_META_TITLE);
128             }
129              
130 4           static PDFMAKE_INLINE const char *pdfmake_meta_get_author(pdfmake_doc_t *doc) {
131 4           return pdfmake_meta_get(doc, PDFMAKE_META_AUTHOR);
132             }
133              
134 3           static PDFMAKE_INLINE const char *pdfmake_meta_get_subject(pdfmake_doc_t *doc) {
135 3           return pdfmake_meta_get(doc, PDFMAKE_META_SUBJECT);
136             }
137              
138 3           static PDFMAKE_INLINE const char *pdfmake_meta_get_keywords(pdfmake_doc_t *doc) {
139 3           return pdfmake_meta_get(doc, PDFMAKE_META_KEYWORDS);
140             }
141              
142 3           static PDFMAKE_INLINE const char *pdfmake_meta_get_creator(pdfmake_doc_t *doc) {
143 3           return pdfmake_meta_get(doc, PDFMAKE_META_CREATOR);
144             }
145              
146 2           static PDFMAKE_INLINE const char *pdfmake_meta_get_producer(pdfmake_doc_t *doc) {
147 2           return pdfmake_meta_get(doc, PDFMAKE_META_PRODUCER);
148             }
149              
150             static PDFMAKE_INLINE const char *pdfmake_meta_get_creation_date(pdfmake_doc_t *doc) {
151             return pdfmake_meta_get(doc, PDFMAKE_META_CREATION_DATE);
152             }
153              
154             static PDFMAKE_INLINE const char *pdfmake_meta_get_mod_date(pdfmake_doc_t *doc) {
155             return pdfmake_meta_get(doc, PDFMAKE_META_MOD_DATE);
156             }
157              
158             /*----------------------------------------------------------------------------
159             * Trapped field (name value, not string)
160             *--------------------------------------------------------------------------*/
161              
162             typedef enum {
163             PDFMAKE_TRAPPED_UNKNOWN = 0,
164             PDFMAKE_TRAPPED_TRUE = 1,
165             PDFMAKE_TRAPPED_FALSE = 2
166             } pdfmake_trapped_t;
167              
168             pdfmake_err_t pdfmake_meta_set_trapped(pdfmake_doc_t *doc, pdfmake_trapped_t trapped);
169             pdfmake_trapped_t pdfmake_meta_get_trapped(pdfmake_doc_t *doc);
170              
171             /*----------------------------------------------------------------------------
172             * Auto-metadata (called during write)
173             *--------------------------------------------------------------------------*/
174              
175             /*
176             * Set Producer to "PDF-Make/VERSION" if not already set.
177             * Set CreationDate to current time if not already set.
178             * Set ModDate to current time.
179             * Called automatically by pdfmake_doc_write().
180             */
181             void pdfmake_meta_auto_fill(pdfmake_doc_t *doc);
182              
183             #ifdef __cplusplus
184             }
185             #endif
186              
187             #endif /* PDFMAKE_META_H */