Thank you for contacting support.
We are afraid that you may not execute scripts with the API, at the moment. However, a feature request can be logged to execute custom scripts over the document. Something like:
Therefore, please share your source file and expected output as ZIP files so that we may investigate further and help you out.