just use
pdf.js
to render the pages onto an invisible canvas first. once u have the canvas context, u can iterate through the pixel data and apply a simple luminance formula to each pixel. it's way faster than trying to manipulate the raw pdf streams directly.