MCPcopy Create free account
hub / github.com/LibPDF-js/core / getKeywords

Method getKeywords

src/api/pdf.ts:1171–1195  ·  view source on GitHub ↗

* Get the document keywords. * * @returns Array of keywords, or undefined if not set

()

Source from the content-addressed store, hash-verified

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.

Callers 5

getMetadataMethod · 0.95
pdf.test.tsFile · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 4

asStringMethod · 0.80
getObjectMethod · 0.65
getRefMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected