Search code examples
rubyapipdfpdf-generationechosign

Echosign APIs and pre-populating text in a PDF


I have a pdf with several text fields. I have used Echosign's tutorial on creating text tags to create the tags but the Echosign API expert told me that the API method I've been told to use (createURLWidget) does not allow data to be prefilled using the prefill suffix.

I am using Ruby to run the methods.

my field name is full_name and I switched the actual document key with a fake one.

params = 
{
  :name => 'Agreement',
  :document_key => '3434hkfhegeg',
  :mime_type => 'application/pdf',
  :fields => 
  {
    :full_name => 'Mary'
  }
}

the text tags that I've tried are:

full_name_es_:sender:fullname
full_name_es_:signer
full_name_es_:signer1
full_name_es_:signer2
full_name_es_:sender

Here's the naming syntax:

<field_name>_es_<:Role><:Field Type>

I've tried them Read-only and not.

When I run "ruby create_url_widget.rb" in terminal

This is the relevant part of my response:

<mergeFieldInfo><ns9:MergeFields/><ns9:fieldName>full_name</ns9:fieldName>
<ns9:defaultValue>Mary</ns9:defaultValue></ns9:MergeFields></mergeFieldInfo> 

a URL is also generated with the correct PDF embedded in the page on echosign's site. However, no text has been places where the full_name field is located. If I have made that text "read-only," it's no longer a box to fill-in, if I make it required, the box is red-outlined and when I have a date text tag that I test, it fills it in appropriately so I know it's doing something.

I have used soupUI to try to change up my code with still no luck.

If anyone needs more code from me, let me know. If anyone has any suggestions, let me know, I am really stuck. I don't even know for sure if this API method will do this for sure, does anyone know this or should I be using another method?

Thank you for your time in advance!


Solution

  • I solved it! I needed to add a MergeField parameter in addition to the pre-existing mergeFieldInfo and mergeFields. Since each text field needed it's own MergeField parameter, it had to be placed within the each_pair do loop.

    code in my xml builder:

    if has?( :fields, Hash )
      xml.mergeFieldInfo do
         xml.tag! 'ns9:mergeFields' do
           fields.each_pair do | key, value |
             xml.tag! 'ns9:MergeField' do 
               xml.tag! 'ns9:fieldName', key.to_s
               xml.tag! 'ns9:defaultValue', value.to_s
             end
           end
         end
      end
    end
    

    working text tag example:

    full_name_es_:signer1
    

    what my response looks like:

    <mergeFieldInfo><ns9:mergeFields>
    <ns9:MergeField><ns9:defaultValue>Kristoph</ns9:defaultValue><ns9:fieldName>full_name</ns9:fieldName></ns9:MergeField>
    <ns9:MergeField><ns9:defaultValue>123 Mockingbird Lane</ns9:defaultValue><ns9:fieldName>address_1</ns9:fieldName></ns9:MergeField>
    </ns9:mergeFields></mergeFieldInfo>