Only works on latest macOS. Also you have to wait a bit for the OCR to take place and there are no indication whatsoever the system is working on it. When it’s done, you can simply select the text.
I have had this pdf open in Preview for 30+ min in the latest macOS. I think this is the Live Text functionality mentioned in other comments, but it does not work on PDFs, only images and whatnot.