Javascript dependencies

Hi, I am working with PDF files with form data that I need to extract. I can manually flatten prior to upload, but that will not work for clients. Is there a way to flatten a PDF file in order to extract form field data? When I tried to create a custom function it wanted PDF-lib. Is there any other way to do this?