* Get the document keywords. * * @returns Array of keywords, or undefined if not set
()
| 1169 | * @returns Array of keywords, or undefined if not set |
| 1170 | */ |
| 1171 | getKeywords(): string[] | undefined { |
| 1172 | const infoRef = this.ctx.info.trailer.getRef("Info"); |
| 1173 | |
| 1174 | if (!infoRef) { |
| 1175 | return undefined; |
| 1176 | } |
| 1177 | |
| 1178 | const info = this.ctx.registry.getObject(infoRef); |
| 1179 | |
| 1180 | if (!(info instanceof PdfDict)) { |
| 1181 | return undefined; |
| 1182 | } |
| 1183 | |
| 1184 | const keywordsStr = info.getString("Keywords"); |
| 1185 | |
| 1186 | if (!keywordsStr) { |
| 1187 | return undefined; |
| 1188 | } |
| 1189 | |
| 1190 | const keywords = keywordsStr.asString(); |
| 1191 | |
| 1192 | // Split on whitespace, filter empty strings |
| 1193 | // Returns empty array for empty string (which is valid - explicitly set to no keywords) |
| 1194 | return keywords.split(/\s+/).filter(k => k.length > 0); |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Set the document keywords. |
no test coverage detected