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

Method fromString

src/objects/pdf-string.ts:44–49  ·  view source on GitHub ↗

* Create a PdfString from text (auto-selects encoding). * * Uses PDFDocEncoding if all characters fit, otherwise UTF-16BE with BOM. * PDFDocEncoding supports ASCII, Latin-1 supplement, and some special chars * (€, •, —, ", ", etc.). For CJK, emoji, or other Unicode, uses UTF-16BE.

(text: string)

Source from the content-addressed store, hash-verified

42 * (€, •, —, ", ", etc.). For CJK, emoji, or other Unicode, uses UTF-16BE.
43 */
44 static fromString(text: string): PdfString {
45 const bytes = encodeTextString(text);
46 // Use hex format for UTF-16 (has BOM, cleaner output), literal for PDFDoc
47 const format = canEncodePdfDoc(text) ? "literal" : "hex";
48 return new PdfString(bytes, format);
49 }
50
51 /**
52 * Create a PdfString from a hex string (e.g., "48656C6C6F").

Callers

nothing calls this directly

Calls 2

encodeTextStringFunction · 0.90
canEncodePdfDocFunction · 0.90

Tested by

no test coverage detected