@@ -131,21 +131,24 @@ function getNestedNumberArray(dictionary: PDFDict, key: string, index = 0): numb
131131}
132132
133133function readAnnotationsWithRealPdfJs ( fixturePath : string ) : Array < Record < string , unknown > > {
134+ const outputMarker = '__INKLAYER_PDFJS_ANNOTATIONS__'
134135 const script = [
135136 "import { readFileSync } from 'node:fs'" ,
136137 "import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'" ,
137138 'const task = getDocument({ data: new Uint8Array(readFileSync(process.argv[1])) })' ,
138139 'const document = await task.promise' ,
139140 'const page = await document.getPage(1)' ,
140141 'const annotations = await page.getAnnotations()' ,
141- 'process.stdout.write(JSON.stringify(annotations, (_key, value) => ArrayBuffer.isView(value) ? Array.from(value) : value) )' ,
142- 'await task.destroy()'
142+ 'await task.destroy( )' ,
143+ `process.stdout.write(' ${ outputMarker } ' + JSON.stringify(annotations, (_key, value) => ArrayBuffer.isView(value) ? Array.from(value) : value))`
143144 ] . join ( ';' )
144145 const output = execFileSync ( process . execPath , [ '--input-type=module' , '-e' , script , fixturePath ] , {
145146 encoding : 'utf8' ,
146147 timeout : 5000
147148 } )
148- return JSON . parse ( output ) as Array < Record < string , unknown > >
149+ const markerIndex = output . lastIndexOf ( outputMarker )
150+ if ( markerIndex === - 1 ) throw new Error ( 'PDF.js annotation subprocess returned no result marker.' )
151+ return JSON . parse ( output . slice ( markerIndex + outputMarker . length ) ) as Array < Record < string , unknown > >
149152}
150153
151154function getPpmPixels ( data : Buffer ) : { width : number ; height : number ; pixels : Buffer } {
0 commit comments