Although JXA is quite capable, there are some things that are difficult or impossible to achieve with it alone. For example, printing only certain pages of a PDF document via a script or extracting all images from an HTML document is not easily feasible with a script.
Whenever JXA falls short, you can try to find an alternative solution by calling out to the frameworks included with macOS. Apple provides an ObjC-JXA-bridge for that: From your JXA script, you can call ObjC methods and use their return values.
This is described further in Marrying JXA with ObjC.