MCPcopy Index your code
hub / github.com/simstudioai/sim / extractPdfFromBuffer

Function extractPdfFromBuffer

apps/sim/lib/pptx-renderer/utils/emf-parser.ts:171–190  ·  view source on GitHub ↗

* Search for %PDF...%%EOF in a buffer and extract the PDF bytes.

(buf: Uint8Array)

Source from the content-addressed store, hash-verified

169 * Search for %PDF...%%EOF in a buffer and extract the PDF bytes.
170 */
171function extractPdfFromBuffer(buf: Uint8Array): Uint8Array | null {
172 const pdfStart = findSequence(buf, PDF_HEADER)
173 if (pdfStart === -1) return null
174
175 // Search for %%EOF from the end (PDF may have multiple %%EOF; take the last one)
176 let pdfEnd = -1
177 for (let i = buf.length - PDF_EOF.length; i >= pdfStart; i--) {
178 if (matchesAt(buf, i, PDF_EOF)) {
179 pdfEnd = i + PDF_EOF.length
180 break
181 }
182 }
183
184 if (pdfEnd === -1) {
185 // No %%EOF found — take everything from %PDF to end of buffer
186 pdfEnd = buf.length
187 }
188
189 return buf.slice(pdfStart, pdfEnd)
190}
191
192/**
193 * Parse a STRETCHDIBITS record and extract the bitmap as ImageData.

Callers 2

parseGdiCommentFunction · 0.85
parseMultiformatsFunction · 0.85

Calls 2

findSequenceFunction · 0.85
matchesAtFunction · 0.85

Tested by

no test coverage detected