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

Method getTitle

src/api/pdf.ts:1058–1072  ·  view source on GitHub ↗

* Get the document title. * * @returns The title, or undefined if not set * * @example * ```typescript * const title = pdf.getTitle(); * if (title) { * console.log(`Document: ${title}`); * } * ```

()

Source from the content-addressed store, hash-verified

1056 * ```
1057 */
1058 getTitle(): string | undefined {
1059 const infoRef = this.ctx.info.trailer.getRef("Info");
1060
1061 if (!infoRef) {
1062 return undefined;
1063 }
1064
1065 const info = this.ctx.registry.getObject(infoRef);
1066
1067 if (!(info instanceof PdfDict)) {
1068 return undefined;
1069 }
1070
1071 return info.getString("Title")?.asString();
1072 }
1073
1074 /**
1075 * Set the document title.

Callers 10

getMetadataMethod · 0.95
pdf.test.tsFile · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 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