Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Disabling the paste function in a text field

Community Beginner ,
Feb 24, 2016 Feb 24, 2016

I am creating a PDF form and am wanting to restrict the user so they cannot paste text from another source into a text field on the form.  Is this possible?

I am using Acrobat Pro DC.

Thanks.

TOPICS
Acrobat SDK and JavaScript , Windows
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 24, 2016 Feb 24, 2016

The custom keystroke script (Text Field Properties dialog > Format tab > Custom format category > Custom Keystroke Script) can be as simple as:

event.rc = event.change.length < 2;

The problem is if you need to do this for fields that use one of the built-in formatting categories (e.g., Number or Date), then it gets more complicated.

Translate
LEGEND ,
Feb 24, 2016 Feb 24, 2016

In a keystroke script you can reject anything that's more than a single character, as would happen if multiple characters were pasted. This would still allow the user to paste a single character at a time. Would that be OK?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 24, 2016 Feb 24, 2016

If that is something I can setup easily that would be fine.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2016 Feb 24, 2016

The custom keystroke script (Text Field Properties dialog > Format tab > Custom format category > Custom Keystroke Script) can be as simple as:

event.rc = event.change.length < 2;

The problem is if you need to do this for fields that use one of the built-in formatting categories (e.g., Number or Date), then it gets more complicated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 24, 2016 Feb 24, 2016

Thank you very much.  That works fine for what I need to do.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2020 Apr 19, 2020

Awesome - thank you 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 04, 2023 Jan 04, 2023

I see how this works, but when I tried on my document I found that I could only access the format tab when a single field is selected. Is there a way to do this for an entire document at once, or at least an entire page at once?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2023 Jan 04, 2023

Yes, you can write a console script to apply the custom keystroke to a whole set of fields all at once.  

Read this. 

https://www.pdfscripting.com/public/Editing-Fields-Properties.cfm?sd=40#JScript

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2024 Oct 01, 2024

It worked. However if I open the form with a browser, pasting text in the field is allowed. Any suggestions?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2024 Oct 01, 2024

There's nothing to do about it. Most browser PDF plugins are sub-par when it comes to scripts and form fields.

You can complain to the developers of these plugins, but the real solution is to instruct the users to open the file in Reader if they want it to work correctly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2024 Oct 01, 2024

Is there a way to ensure that the PDF file only opens in Adobe Acrobat?

Note: For reference, Firefox is currently the only browser that maintains keystroke restrictions.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2024 Oct 01, 2024

Not really. You can include a large warning text, though, and hide it with a script when the file is opened. So if scripts don't work the warning will be hidden.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2024 Oct 01, 2024
LATEST

I am a Technologist and I assist college professors. The scope was to avoid students to paste text generated by Chat GPT into the forms. Thank you very much for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines