How to get fillable PDF to prompt for required fields when user saves? - pdf

I've created a fillable PDF form using Acrobat 10. I see where you can set form fields to be required, but all that does is outline the fields in red.
How can I get a prompt asking users to enter data in the required fields when they hit save?

You need to use Adobe-JavaScript if you want to achieve this.
Read this page in the Adobe documentation for more details:
Enforcing Required Fields
From that page, the code you have to include in your PDF file will look like this:
f = getField(event.target.name)
if (f.value.length == 0)
{
f.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("This field is required. Please enter a value.")
}
More details about the pop-up alert can be found here:
https://acrobatusers.com/tutorials/popup_windows_part1

Related

Filling multiple fields in PDF form using PDFBOX and Lock editing of pdf document after filling

I am new to PDF BOX, need to fill the information in PDF Form, which has sections and field names:
PDF form contains information of
NAME
and box to fill the information
Address
and box to fill the information
City
box to fill the information.
if i have the Name, Address and city information how to fill that into the pdf form using pdf box.
Have used the example from PDFbox, acroForm only fills sample fields how to get this filled with particular information at particular field.
once after filling it how to make it locked.
String formTemplate = "C:/FillFormField.pdf";
PDDocument pdfDocument = PDDocument.load(new File(formTemplate))
// get the document catalog
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
// as there might not be an AcroForm entry a null check is necessary
if (acroForm != null)
{
// Retrieve an individual field and set its value.
PDTextField field = (PDTextField) acroForm.getField( "sampleField" );
field.setValue("Text Entry");
// If a field is nested within the form tree a fully qualified name
// might be provided to access the field.
field = (PDTextField) acroForm.getField( "fieldsContainer.nestedSampleField" );
field.setValue("Text Entry");
}
// Save and close the filled out form.
pdfDocument.save("C:/FillFormField.pdf");
Currently dont have errors above code is working to fill out some junk fields.
need to fill exactly the Name with box info with Name information
Address with box info with Address information
I am able to do it with PDF Debugger from PDFBOX.
Used CMD prompt to get the structure of the file
java -jar pdfbox-app-1.8.10.jar PDFDebugger yourfile.pdf
please get the above jar file from apache PDF box.
once you able to see the structure, find the fields name.
For my purpose of locking, i dont need to use the encryption method. so used Acroform Flatten PDF method.
// flatten() method saves the PDF read only
acroForm.flatten();

ABC PDF version 6.0 Form Fields Read Only

We have a VB.NET program that is using Supergoo's ABCPDF version 6.1.1.2. Our program takes standard XML strings and places values in a corresponding PDF form field on the template PDF.
Problem:
We have over 3000 PDF files that have all been "tagged" with form fields. There could be up to 50 form fields on the template PDFs for a total of roughly 150,000 form fields in use potentially. We have noticed that some of these form fields have their form field common properties set to hidden by mistake. (see screenshot)
The issue is that the PDF coming back after the string values have been added are not showing up. Duh right? Fix the form field property and call it done. However, there is no way to know how many other of the other 150,000 form fields have been improperly tagged like this.
Does anyone know if I can adjust the PDF generation program to forcefully ignore that form field common property? Here is a sample of the vb.net code I am hoping to slightly alter...
Dim theDoc As Doc = New Doc
theDoc.Form.Fields("SampleFieldName").?????? 'can we set something here to ignore the hidden property?
According to the docs at
http://www.websupergoo.com/helppdfnet/source/6-abcpdf.objects/field/2-properties/page.htm
The .Page property of a Field object will tell you the page the field is on. Since Page is a class, if the result 'Is Nothing' then you know that the field is not visible since it doesn't appears on any page in the PDF document.
Please note that there are a few caveats when using fields that are not hidden but not actually visible when rendered (being too small, being spread on two pages, etc). If you need need to handle that you may be interested in http://www.websupergoo.com/helppdfnet/source/6-abcpdf.objects/field/2-properties/rect.htm depending on your use cases.
For the ABCPDF v6 software, I have discovered through Mihai's suggestion that it is possible. I have coded this C# example in the hopes that it helps someone down the road...
static void SetFillableFieldsToWriteableExample(string origFileLocation, string newFileLocation)
{
Doc theDoc = new Doc();
theDoc.Read(origFileLocation);
var theFields = theDoc.Form.GetFieldNames();
foreach (string theField in theFields)
{
Field theFieldInstance = theDoc.Form[theField];
theDoc.SetInfo(theFieldInstance.ID, "/F", "4");
}
theDoc.Save(newFileLocation);
}
I have tested this and it works when all fields are text fields on the PDF. Not sure on the other field types.
This code should not be used in a production environment as written here. There is no guarantee that the origFileLocation or newFileLocation references a PDF and no error handling among other issues. This is for demonstration purposes only.

Smartforms: form has wrong page format

SAP 730 Final Release Build 1429747 Patch Level 5
I am modifying a purchase order form; the form has a First and Next page; I added a Secondary window named 'Buyer' to both pages; before I add any elements, when I print preview the form I get the error
Form BUYER has wrong page format.
Message no. SSFCOMPOSER026
The Page Format in Form Attributes is LETTER; there is no different page format for this window.
I've read that this can be the result of some text areas containing too much text, however this window has no elements (yet).
Anyone run in to this issue before? Many thanks. I can post more info if needed.
Form TXT_CONTACT has wrong page format.
Message no. SSFCOMPOSER026
Diagnosis
Form TXT_CONTACT has a different page format than the forms output previously but has been added to the same spool request.
System Response
Form TXT_CONTACT ist not processed.
Procedure
While forms are formatted (FM SSFCOMP_OPEN to FM SSFCOMP_CLOSE), the page format must not be changed. All forms within one spool request must have the same page format.
The first page format used, in this case paper format , is applicable to all subsequent forms.

Storing a hidden, non-editable variable in a form. Word 97 Compatible

I need a non-editable field in a word form that can be read in vba.
Currently I use a text field, which is hidden. As in:
ActiveDocument.FormFields("DocID").Select
Selection.Font.Hidden = false
//do read then re-hide it.
However users can still 'tab' in to this text field and overwrite the document ID that is there and thus invalidate the vba macro. And unfortunately that is what happens.
I can set the text field property 'Fill-in enabled' to false which gives the desired effect in the form, i.e the user cannot edit it. However now this text field cannot be read in vba.
ActiveDocument.FormFields("DocID").SomeProperty
//throws error 'The requested member of the collection does not exist'
So my question is, is there a way I can store a hidden variable in a word form that can be read in a vba macro?
Unfortunately this has to be a Word-97 compatible solution.
You could use custom document properties instead, see here:
http://msdn.microsoft.com/en-us/library/aa537154(v=office.11).aspx

Validating Attachment in Richtext field

I am using below code to validate the Attachment in Richtext field.
If I will not used Call source.Refresh(True)
then validation is not working, but this code is also refreshing document everytime querysave is called in buttons.
So is there any option or any other idea so that I should not user this Refresh part or entire code to validate .
If anybody have more efficient code then please share this.
If Source.Document.YesNo20(0)="Yes" Then
Call source.Refresh(True)
Dim rtitem As NotesRichTextItem
Set rtitem = source.Document.GetFirstItem( "Atchmnt20" )
NotesEmbeddedObjectArray = rtitem.EmbeddedObjects
If Isempty ( NotesEmbeddedObjectArray ) Then
Messagebox "Please enter an attachment in 20a. As you selected option Yes"
continue=False
Exit Sub
End If
End If
There's a way in LotusScript to check attachments presence even for new (not saved) documents.
Create a hidden computed field, for instance AttachmentNames with formula:
#If(#AttachmentNames!=""; "1"; "");
In LotusScript do the following:
'in new documents Form field may be empty
If doc.Form(0) = "" then
doc.Form = "YourFormAlias"
End If
'computing doc contents with the form
call doc.ComputeWithForm(false, false)
If doc.AttachmentNames(0) = "" then
MsgBox "Please attach a file",,"Attention"
Continue = False 'if you are running this code in QuerySave
Exit Sub
End If
Validating rich text fields in Lotus Notes is a bit of a dark art, but can you not just do this? (where doc is the back-end):
If(doc.HasEmbedded) Then Continue = True
There are other things you can do. Check this Lotus Developer Domain post, which covers attachments, text, embedded objects, all sorts:
http://www-10.lotus.com/ldd/nd6forum.nsf/0/8b3df10667d355768525719a00549058
Can you validate RT field with formula?
I created a hidden field below my rich text field with this Input Validation formula:
REM {Validate just when saving};
#If(!#IsDocBeingSaved; #Return(#Success); "");
REM {Should contain some file};
_filenames := #AttachmentNames;
#If(
#Elements(_filenames)=0;
#Return(#Failure("You should attach at least one file"));
#Success);
Assuming that you want to avoid the Refresh because it takes too long, here is what you may want to look at and if feasible, try to change:
Maybe you can use the "Entering" event of the RichText field in conjunction with a global variable (in the form) to skip the Refresh in your code, if the RichText field wasn't touched at all.
Are there keyword fields with "Refresh choices on document refresh" option enabled that may be safe to disable? Or even place a button that would bring up a dialog and populate the field with the selected keyword(s) - refreshing the choices won't be neccessary then, as you can always present up-to-date choices through #DbColumn/#DbLookup or NotesUIWorkspace.PickListStrings.
Is there any code (LotusScript or Formula) in "Queryrecalc" and/or "Postrecalc" form events that may be possible to optimize? For example by using a global variable (in the form) as a flag whether to execute the code in Queryrecalc/Postrecalc - set it to false just before calling Refresh in your code, then set it back to true (because this Refresh only serves to update the RichText field to the backend document).