* Embed a JPEG image into the document. * * JPEG images are embedded directly using DCTDecode filter, * which means the JPEG data is stored as-is without re-encoding. * * @param bytes - JPEG file bytes * @returns PDFImage that can be drawn with page.drawImage() * @throws {Error}
(bytes: Uint8Array)
| 2128 | * ``` |
| 2129 | */ |
| 2130 | embedJpeg(bytes: Uint8Array): PDFImage { |
| 2131 | const info = parseJpegHeader(bytes); |
| 2132 | |
| 2133 | // Create XObject image stream with DCTDecode filter |
| 2134 | const stream = PdfStream.fromDict( |
| 2135 | { |
| 2136 | Type: PdfName.of("XObject"), |
| 2137 | Subtype: PdfName.of("Image"), |
| 2138 | Width: PdfNumber.of(info.width), |
| 2139 | Height: PdfNumber.of(info.height), |
| 2140 | ColorSpace: PdfName.of(info.colorSpace), |
| 2141 | BitsPerComponent: PdfNumber.of(8), |
| 2142 | Filter: PdfName.of("DCTDecode"), |
| 2143 | }, |
| 2144 | bytes, |
| 2145 | ); |
| 2146 | |
| 2147 | const ref = this.register(stream); |
| 2148 | |
| 2149 | return new PDFImage(ref, info.width, info.height); |
| 2150 | } |
| 2151 | |
| 2152 | /** |
| 2153 | * Embed a PNG image into the document. |
no test coverage detected