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

Method embedImage

src/api/pdf.ts:2098–2108  ·  view source on GitHub ↗

* Embed an image (JPEG or PNG) into the document. * * Automatically detects the image format and calls the appropriate * embedding method. The returned PDFImage can be drawn on pages * using `page.drawImage()`. * * @param bytes - Image file bytes (JPEG or PNG) * @returns PDFImag

(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

2096 * ```
2097 */
2098 embedImage(bytes: Uint8Array): PDFImage {
2099 if (isJpeg(bytes)) {
2100 return this.embedJpeg(bytes);
2101 }
2102
2103 if (isPng(bytes)) {
2104 return this.embedPng(bytes);
2105 }
2106
2107 throw new Error("Unsupported image format. Only JPEG and PNG are supported.");
2108 }
2109
2110 /**
2111 * Embed a JPEG image into the document.

Callers 5

drawing.test.tsFile · 0.80
factory.test.tsFile · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 4

embedJpegMethod · 0.95
embedPngMethod · 0.95
isJpegFunction · 0.90
isPngFunction · 0.90

Tested by

no test coverage detected