ChatGPT Prompt for Working Acrobat JavaScript
Copy link to clipboard
Copied
Hi all,
I am not a coder by trade but see how much value there is in writing some JavaScript code that can automate some of our Production/Pre-Flight work.
My current prompting generates code that won't execute without error.
Is there any prompting/prompt input folks could recommend to get ChatGPT to generate code that uses the Acrobat API and JavaScript that is exclusively compatible with Adobe Acrobat?
For reference, here is my current prompt:
I would like to write a script for Adobe Acrobat Professional 2022. Please use JavaScript 1.5 of ISO-16262 (formerly ECMAScript), and nothing newer or more modern. Please use detailed comments. The script should be compatible with the Execute JavaScript feature in the Action Wizard. This script should ONLY use features and function calls available in the Acrobat JavaScript API. Ensure all variables are defined at the maximum scope and accessible in all blocks and functions.
The script should set the PDF to edit mode first, as it will be making changes to the content. Then, iterate through all pages in the pdf. For each even page: if there is any content that is not whitespace (not just annotations, but any content including text, images, or otherwise) in right 0.4 inch margin, move the entire contents of the page to the left until all non-whitespace content is outside of this margin. If moving the page would cause any page content to overflow outside of the page, instead, move the content as far as possible, and then shrink the page the minimum amount necessary to ensure no non-whitespace content is in the rightmost 0.4 inch right margin. If after these actions, any non-whitespace content is over the left 0.2 inch margin, shrink the page until all content is within the 0.2 inch left margin, and 0.4 inch right margin.
A dialog box should be shown when the script starts running and let the user know that another dialog box will show upon completion. A dialog box should be shown when the script is done running.
Copy link to clipboard
Copied
ChatGPT, like all AI, is a pattern engine. It's been trained on an extremely wide range of written patterns. The text it generates follows patterns suggested in the prompt. These results have literally nothing to do with the reality behind the prompt. Chapt GPT has no reality check, no fact checking. Really, no idea of what it is doing (cause you know it's not sentient). The results are akin the simple fantasy's of a happy idiot.
It is currently possible to create an AI for a narrow purpose, such as coding in a specific environment with a specific language. But something like ChatGPT is only capable of creating hallucinations untethered from reality.
If you want working code, you need to actually learn how to code, or hire someone who has spent the time and effort to do so. Pretending to do something is not a short cut to actually doing something.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
ChatGPT is good for some programming tasks, but we've seen it has a lot of issues when it comes to Acrobat JS.
The biggest problem it has, in my opinion, is that it doesn't say when things are not possible. It just invents solutions (which don't work) to try and make such impossible tasks work.
For example: The script should set the PDF to edit mode first, as it will be making changes to the content.
This is not possible with a script. Also, moving a page's contents is not possible to do directly. You would need to re-crop the page in order to achieve something like it, and that can be quite tricky.
My recommendation is to hire someone who knows what they're doing instead of relying on AI for such a task.
Copy link to clipboard
Copied
Thanks for sharing your prompt. I'm probably in the same situation, I'm not a coder and I don't know JavaScript or even HTML. However, I managed to fix some javascript codes for Adobe Acrobat using chat GPT by texting and using logic. From my experience so far, it took a very long time to chat and find the best solution but it did a good job of fixing errors and creating features that some experts in this forum said were not possible. If you know what you want and can think logically, you will spend less time to achieve the results you want. If you are struggling to get the right result, you can copy a reference text from the Adobe javascript API documentation or any idea someone gave you in the forums, sample codes that could offer a solution etc...
I don't think Chat GPT can easily create codes from nothing at the moment, but it can definitely be of help to edit and improve existing ones. Every single message I send it's useful to remind him about the Adobe Acrobat environment, and to keep the code as original as possible as it keeps being "super proactive" and changing/breaking things that were fine and are not necessary to edit.

