Aloaha PDF Forms API

The Aloaha PDF Forms API can be used to access PDF Form Fields programmatically. Please find below an overview of the possible functions. Please note that the Aloaha PDF Saver  Professional  is required. It is not possible with the Standard Edition of the Aloaha PDF Form Saver.

To be able to access the functions please create the object.

Dim PDF
set PDF = createobject("aloahapdf.edit")


Next you need to load the PDF Form to be edited to memory. The parameter can be a local file or a remote file hosted on a webserver. For example http://www.aloaha.com/cache/fs5.pdf

If PDF.load_pdf_to_mem(cstr(c:\form.pdf)) =true then
          msgbox "Form loaded to memory"
          if PDF.FormFields>0 then
                            msgbox "PDF is Form"
          else
                            msgbox "PDF is not a Form"
                            call PDF.unload_pdf_from_mem
          end if
else
         msgbox "Could not load Form to memory"
end if



To be able to set or read a Form Value you need to select the FormField.

Form Fields can be selected by ID Number or FormTitle. To select a FormField by ID Number is faster. IDs always start at 1.

if PDF.SelectFormField(clng(1))=true then
         msgbox "First FormField selected"
else
         msgbox "Could not select FormField"
end if

In case the ID Numbers of your Form are not known its easier to select the the FormField by Title.

dim FormFieldID
FormFieldID=PDF.SelectFormFieldbyTitle(cstr("FirstName"))
if FormFieldID>0 then
          if PDF.SelectFormField(clng(FormFieldID))=true then
                    msgbox "FormField "&cstr("FirstName")&" with ID Number "&cstr(FormFieldID)&" selected"
         else
                    msgbox "Could not find FormField"
         end if
else
         msgbox "Could not find FormField"
end if

Sometimes FormFields can contain SubObjects. To detect such an subobject please call

If PDF.FormFieldSubs>0 then
        msgbox "Form Field contains Subjobjects"
end if



In case a FormField contains subjobjects you can call SelectFormFieldSub to select one of such objects. 

if PDF.SelectFormFieldSub(2)=true then
         msgbox "Subobject 2 selected"
else
         msgbox "Could not select Subobject"
end if


Now you can set or read the formfield value.

To Read the FormField Value call:

msgbox PDF.GetPossibleFieldValue

To set a value call the following code:

if PDF.SetFormFieldValue(cstr("This is the new value"))=true then
          msgbox "Value set"
else
         msgbox "Could not set Value"
end if 

After you set all required values you must save the PDF Document from Memory to Disk.

Please use the command save_pdf_to_file:

if PDF.save_pdf_to_file(cstr("c:\targetpdf.pdf"))=true then
         msgbox "PDF Saved to Disk"
else
         msgbox "Could not Save PDF to Disk"
end if

Now remove the PDF Object from memory if you do not need it anymore. 

set PDF = Nothing




Additional Form Field Functions


1. get_formfieldTitle(FieldID) returns the Form Field Title for a given FieldID.

2. get_fieldValue_byTitle(FormFieldTitle) returns the form field value for a given Field directly whithout selecting it before.

3. SetFormFieldValue_by_Name(FormFieldTitle, NewValue) sets Form Field by Title. It works directly without having to select the field before.

4. SetFormFieldValue_by_ID(FieldID, NewValue) sets Form Field by Formfield ID. It works directly without selecting the field before.

5. seal_all_fields flattens all form fields

6. sealform(FieldID) seals/flattens given Formfield

7. set_formFieldReadOnly(FieldID) sets a Formfield read only.

8. make_all_fields_readonly renders all Formfields read-only.

9. delete_formfield deletes a formfield by ID

10. set_FormFieldVisible can be used to toggle a field visible or unvisible.

11. set_formfield_color sets colors of fields

12. set_formfield_bordertype defines the bordertype of a field

13. set_formfield_position sets/moves a field to a given position.

14. Submit_Button_Create creates a button to post XML data to a webserver

15. Submit_Button_set_URL defines the target of 14

16. is_button checks if a formfield is of type button.

17. change_FieldCaption changes the Caption of a Field. For example the text on a button.

18. Enum_Form_Infos returns a collection of all form fields of the document inclusive the form field information like caption, size, position etc.

 Demo.zip (25,84 KB)

Please ask...

Although we really tried hard, there are always questions left open. But perhaps somebody else had already put the same question?
Please check!
  • Hi,
    When using GetFormFieldTitle(FieldID) I get an error "Object doesn't support this property or method". Why?

    Please use get_formfieldTitle(clng(fieldID))
    Answered 23.04.2010
  • Do you have help documentation?
  • I'm looking to take a web form, and have a submit button essentially that then creates a pdf document using form values from the web page. Is your software capable of doing something like this.
If not, please do not hesitate to send us your question.
We would be glad to answer it.
PDF SDKPDF Form Saver SDKPDF Forms APIPDF Forms OCXDelphi ActiveXMerge XML with PDFExport XML DataAdd Submit ButtonDynamik Time StampSmart Card APIAloaha Web ServicesAloaha Print MonitorAloaha Remote ConfigurationWebDAVLDAP ClientProgramming Office MacrosIIS Event Sinks