Hello everyone,
Does anyone know whether it's possible to prevent only scaling of a PDF object using JavaScript?
Use case:
We have a custom tool that adds stamps to a document.
Users should be allowed to move the stamps around, but not scale them.
So locking wouldn't be an option ..
Is that possible?
As far as I'm aware of the properties of PDF objects, I don't think so.
But maybe there's a workaround?
For example, an event listener running in the background that monitors the rect property of these stamps or simply warns the user?
Best regards,
Niklas
Prevent Scaling on PDF Object Using JavaScript
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 22
- Joined: Fri Mar 14, 2025 2:34 pm
-
- Site Admin
- Posts: 11586
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Prevent Scaling on PDF Object Using JavaScript
Hello, HQue
Not in a realistic manner. You could possibly create a custom JS tool to handle the moving process, which simply would not allow users to access the scale values, but that would be a text based input system (similar to our transform tools), and in the end, would need to be manually installed by everyone for that kind of use, in practice even if they did so, it would not prevent them from just using any PDF softwares own inbuilt comment editing tools, to resize it.
So in the end, the answer would have to be a resounding no. There is no property than can be set in a PDF comment to prevent applications from interacting with a comments scale, while still allowing other modification actions like movement.
Kind regards,
Not in a realistic manner. You could possibly create a custom JS tool to handle the moving process, which simply would not allow users to access the scale values, but that would be a text based input system (similar to our transform tools), and in the end, would need to be manually installed by everyone for that kind of use, in practice even if they did so, it would not prevent them from just using any PDF softwares own inbuilt comment editing tools, to resize it.
So in the end, the answer would have to be a resounding no. There is no property than can be set in a PDF comment to prevent applications from interacting with a comments scale, while still allowing other modification actions like movement.
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
-
- User
- Posts: 22
- Joined: Fri Mar 14, 2025 2:34 pm
Re: Prevent Scaling on PDF Object Using JavaScript
Thanks for you answer Daniel!Daniel - PDF-XChange wrote: ↑Mon Aug 04, 2025 6:31 pm Not in a realistic manner. You could possibly create a custom JS tool to handle the moving process, which simply would not allow users to access the scale values, but that would be a text based input system (similar to our transform tools), and in the end, would need to be manually installed by everyone for that kind of use, in practice even if they did so, it would not prevent them from just using any PDF softwares own inbuilt comment editing tools, to resize it.
Hm , but I think the approach you described might actually be enough for our use case,
Manual installation would be possible and we only use XChange Editor ...
Could you provide any guidance on how to implement that?
Like having an event listener that tracks processes in general?
Best and thanks,
Niklas
-
- Site Admin
- Posts: 11586
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Prevent Scaling on PDF Object Using JavaScript
Hello, HQue
To clarify, the potential for a JS solution was not to say that it is in any way possible to prevent people exclusively from using the resize function, no listener or solution I can provide would be able to prevent that, you would need an SDK license, to change such a fundamental aspect of our software, and I am unsure if it could be a toggleable setting. At the vest least, there is absolutely no way to save that kind of special-data in the document itself for use between sessions (it would go against the spec, and could damage your file).
The best scenario I could suggest would be full locking the comments in question, so they can only be accessed via JS, which opens with a "readOnly=False" function, then performs and action, and promptly sets readonly back to true for the comment in question. This of course means no edits at all, are allowed on those comments without toggling the readonly state, and the readonly state would need to be manually applied after each comment is created.
That would be something you need to build on your end, with a JS expert on hand. Unfortunately I am not fluent enough to help create a script, I just have a halfway decent eye for catching common syntax errors, and may be able to help with basic debugging once you have something mostly functional.
If you want to try you hand at this, you will want to look at the JS API Reference Manual, which Adobe has provided here: https://opensource.adobe.com/dc-acrobat ... croJS.html
Kind regards,
To clarify, the potential for a JS solution was not to say that it is in any way possible to prevent people exclusively from using the resize function, no listener or solution I can provide would be able to prevent that, you would need an SDK license, to change such a fundamental aspect of our software, and I am unsure if it could be a toggleable setting. At the vest least, there is absolutely no way to save that kind of special-data in the document itself for use between sessions (it would go against the spec, and could damage your file).
The best scenario I could suggest would be full locking the comments in question, so they can only be accessed via JS, which opens with a "readOnly=False" function, then performs and action, and promptly sets readonly back to true for the comment in question. This of course means no edits at all, are allowed on those comments without toggling the readonly state, and the readonly state would need to be manually applied after each comment is created.
That would be something you need to build on your end, with a JS expert on hand. Unfortunately I am not fluent enough to help create a script, I just have a halfway decent eye for catching common syntax errors, and may be able to help with basic debugging once you have something mostly functional.
If you want to try you hand at this, you will want to look at the JS API Reference Manual, which Adobe has provided here: https://opensource.adobe.com/dc-acrobat ... croJS.html
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com