how to read float32array extracted from pdf? #21075
|
actually iam working on a pdf project using pdfjs-dist library any one hear who can make me understand that what my console output is trying to tell and how i get it in it's original form ? code: app.listen(8080,e=>{ const data=new Uint8Array(fs.readFileSync("cnr.pdf")); const loadingTask = pdfjsLib.getDocument({data:data}); loadingTask.promise.then(async (pdf) => { const page = await pdf.getPage(33); }); console: closeStroke: 21 eoFill: 23 constructPath [ 21, [Float32Array(13) [0,0,841.8900146484375,1,595.2760009765625, 841.8900146484375,1, 595.2760009765625,0,1,0,0,4] ],Float32Array(4) [ 0, 0, 595.2760009765625, 841.8900146484375 ] ] |
Replies: 2 comments 3 replies
|
You can check how the array is used in: Line 1488 in ca13d00 |
What your console is showingYou’re logging For each
So the message is: “here is numeric geometry the PDF painter is using,” not encrypted content. If you want the data in a more usable “original” formPick the level you care about:
Small code notes
If you say whether you need text, images, or exact path geometry, the next step is narrower. |

hello@CODE-WITH-CODEER, pdf.js doesn’t have something like getTextContent() but for paths. If you want exact path geometry, getOperatorList() is the right place — there’s no simpler built-in that dumps SVG paths for you.
Those Float32Arrays are just numbers for the path / bbox in PDF user space. To use them you need to walk all operators (not only the one you filtered), and constructPath in canvas.js is the reference for how those arrays are meant to be read — basically you replay the same ops as the renderer and emit whatever format you want (SVG, etc.). That’s extra work, but it’s normal for this use case.
Layers / OCG on canvas vs SVG is a separate problem (visibility and draw order), …