how to add text field in pdf, while creating package
Monday, October 29, 2018 at 02:46amHello,
I am uploading PDF via REST API PHP, along with signer users. 
I want to add an editable text/input field in the PDF, so that users during singing, can enter their account number or any other data as input.
means like they can fill the form while signing and at the end they can sign the document.
I am confuse here how to do that.
In below code there is function "buildPackage". I tried adding documents fields option it gives error. how to add input field so user can enter details while sign process.
      
                                    
 'Package created from template through REST API',
		  'description' => 'Package created with the eSignLive REST API',
		  'emailMessage' => 'This message should be delivered to all signers',
		  'autocomplete' => true,
		  'type' => 'PACKAGE',
		  'visibility' => 'ACCOUNT',
		  'due' => NULL,
		  'language' => 'en',
		  'status' => 'DRAFT',
		  'roles' => 
		  array (
		    0 => 
		    array (
		      'id' => $placeholderId,
				'attachmentRequirements' => 
				  array (
				    0 => 
				    array (
				      'status' => 'INCOMPLETE',
				      'description' => 'contract',
				      'required' => false,
				      'id' => 'attachment1',
				      'comment' => '',
				      'name' => 'Upload, if you have any contract document! Or Click Done.',
				      'data' => NULL,
				    ),
				),
		      'type' => 'SIGNER',
		      'signers' => 
		      array (
		        0 => 
		        array (
		          'id' => $placeholderId,
		          'firstName' => $firstName,
		          'lastName' => $lastName,
		          'email' => $email,
		        ),
		      ),
		      'name' => 'Signer',
		    ),
		  ),
		);
		$packageJSON = json_encode($build);
		$packageId = json_decode($this->sendRequest($this->packageAppend . $templateId . '/clone', $packageJSON, NULL, 'application/json'), true);
		return $packageId;
	}
	//Create package
	public function buildPackage($application_id)
	{
		$application = Application::find($application_id);
		$title 		 = $application->entity_name.' - '.date('d-m-Y');
		/*if(empty($application->directors)){
			return redirect('home/application/'.$application->unique_id.'/signature');
		}*/
		//document fields
		$documents = array();
		$roles 		 = array();
		$i = 1;
		//directors signers  (ID: Signer1 & Signer2)
		if(!empty($application->directors)){
			foreach (unserialize($application->directors) as $key => $value) {
				if(!empty($value['email'])){
	                $roles[] = array(
	                                'id' => 'Signer'.$i,
	                                'type' => 'SIGNER',
	                                'signers' => array(
	                                    array(
	                                        'email' => trim($value['email']),
	                                        'firstName' => trim($value['f_name']),
	                                        'lastName' => trim($value['l_name']),
	                                        'id' => 'Signer'.$i,
	                                    )
	                                ) ,
	                            );
	                $i++;
	            }
			}
		}
		//manager (ID: Manager1)
		$roles[] = array(
                'id' => 'Manager1',
                'type' => 'SIGNER',
                'signers' => array(
                    array(
                        'email' 	=> '[email protected]',
                        'firstName' => 'Victor',
                        'lastName' 	=> 'GR',
                        'id' => 'Manager1',
                    )
                ) ,
            );
		$build = array(
			'autocomplete' => true,
			'type' 	   => 'PACKAGE',
			'status'   => 'DRAFT',
			'documents'=> $documents,
			'roles'    => $roles,
			'name' 	   => $title,
		);
		$packageJSON = json_encode($build);
		$packageId = json_decode($this->sendRequest($this->packageAppend, $packageJSON, NULL, NULL), true);
		return $packageId;
	}
	//Upload document
	public function buildDocument($packageId,$application_id)
	{
		$application  = Application::find($application_id);
		$payment_term = PaymentTerm::where('application_id',$application->id)->first();
		$director  	  = unserialize($application->directors);
		$user = Auth::user();
		$director_count = 1;
		$build = array(
			'fields' => array(
				array(
					'value' => $application->entity_name,
					'name' => 'customer_name',
				) ,
				array(
					'value' => $application->address,
					'name' => 'customer_address',
				) ,
				array(
					'value' => $application->phone,
					'name' => 'telephone',
				) ,
				array(
					'value' => $user->company_name,
					'name' => 'supplier_name',
				) ,
				array(
					'value' => $user->address,
					'name' => 'supplier_address',
				) ,
				array(
					'value' => $user->state.', '.$user->pincode,
					'name' => 'supplier_address2',
				) ,
				array(
					'value' => '',
					'name' => 'email',
				) ,
				array(
					'value' => $application->abn_number,
					'name' => 'abn_number',
				) ,
				array(
					'value' => $payment_term->installment,
					'name' => 'installment',
				) ,
				array(
					'value' => $payment_term->term,
					'name' => 'month',
				) ,
				array(
					'value' => $user->document_fee,
					'name' => 'handling_fee',
				)
			) ,
			'extract' => true,
			'name' => 'GRENKE - EQUIPMENT LEASE AGREEMENT FOR BUSINESS PURPOSES',
			'id' => 'contract'
		);
		if(isset($director[0]['f_name'])){
		//directors
		$build['fields'][] = array(
								'value' => $director[0]['f_name'].' '.$director[0]['l_name'],
								'name' => 'director_name_1',
							);
		}
		if(isset($director[1]['f_name'])){
		$director_count = 2;
		$build['fields'][] = array(
								'value' => $director[1]['f_name'].' '.$director[1]['l_name'],
								'name' => 'director_name_2',
							); 
		}
		//items list 1st
		foreach ($application->items as $key => $value) {
			if(($key+1) == 5){ break; }
		$build['fields'][] = array(
									'value' => $value->description,
									'name' => 'item_'.($key+1),
								);
		$build['fields'][] = array(
									'value' => $value->quantity,
									'name' => 'qty_'.($key+1),
								);
		}
		//items list 2nd full
		if(count($application->items) > 4){
			foreach ($application->items as $key => $value) {
			$build['fields'][] = array(
									'value' => $value->description,
									'name' => 'item_1_'.($key+1),
								);
			$build['fields'][] = array(
									'value' => $value->manufacturer,
									'name' => 'manufacturer_1_'.($key+1),
								);
			$build['fields'][] = array(
									'value' => $value->quantity,
									'name' => 'qty_1_'.($key+1),
								);
			}	
		}
		//items list 3rd
	if(count($application->items) <= 4){	
		foreach ($application->items as $key => $value) {
		$build['fields'][] = array(
									'value' => $value->description,
									'name' => 'item_2_'.($key+1),
								);
		$build['fields'][] = array(
									'value' => $value->manufacturer,
									'name' => 'manufacturer_2_'.($key+1),
								);
		$build['fields'][] = array(
									'value' => $value->quantity,
									'name' => 'qty_2_'.($key+1),
								);
		}
	}else{
		//enter message to first row
		$build['fields'][] = array(
									'value' => "Please see appendix",
									'name' => 'item_2_1',
								);
		$build['fields'][] = array(
									'value' => "/equipment schedule.",
									'name' => 'item_2_2',
								);
	}
		$documentJSON = json_encode($build);
	if($director_count == 2){
		$postdata = "--" . $this->MULTIPART_BOUNDARY . "\r\n";
	    $postdata .= "Content-Disposition: form-data; name=\"file\"; filename=\"application_pdf_form_d_2.pdf\"\r\n";
	    $postdata .= "Content-Type: application/pdf" . "\r\n\r\n";
	    $postdata .= file_get_contents(asset('upload/application_pdf_form_d_2.pdf'));
	    $postdata .= "\r\n\r\n";
	    $postdata .= "--" . $this->MULTIPART_BOUNDARY . "\r\n";
	    $postdata .= "Content-Disposition: form-data; name=\"payload\"\r\n\r\n";
	    $postdata .= $documentJSON;
	    $postdata .= "\r\n\r\n";
	    $postdata .= "--" . $this->MULTIPART_BOUNDARY . "--\r\n";
	}else{
		$postdata = "--" . $this->MULTIPART_BOUNDARY . "\r\n";
	    $postdata .= "Content-Disposition: form-data; name=\"file\"; filename=\"application_pdf_form_d_1.pdf\"\r\n";
	    $postdata .= "Content-Type: application/pdf" . "\r\n\r\n";
	    $postdata .= file_get_contents(asset('upload/application_pdf_form_d_1.pdf'));
	    $postdata .= "\r\n\r\n";
	    $postdata .= "--" . $this->MULTIPART_BOUNDARY . "\r\n";
	    $postdata .= "Content-Disposition: form-data; name=\"payload\"\r\n\r\n";
	    $postdata .= $documentJSON;
	    $postdata .= "\r\n\r\n";
	    $postdata .= "--" . $this->MULTIPART_BOUNDARY . "--\r\n";
	}
		$status = $this->sendRequest($this->packageAppend . $packageId . '/documents', $documentJSON, $postdata, 'multipart/form-data; boundary=' . $this->MULTIPART_BOUNDARY);
		return $status;
	}
	//Send Package
	public function buildSend($packageId)
	{
		$build = array(
			'status' => 'SENT'
		);
		$sendJSON = json_encode($build);
		$this->sendRequest($this->packageAppend . $packageId, $sendJSON, NULL, 'application/json');
		return NULL;
	}
	//Sender signs consent and contract documents
	public function buildSign($packageId)
	{
		$build = array(
			'documents' => array(
				array(
					'id' => 'contract',
					'name' => 'Application Form'
				)
			)
		);
		$signJSON = json_encode($build);
		$signatureAppend = $this->packageAppend . $packageId . '/documents/signed_documents';
		$this->sendRequest($signatureAppend, $signJSON, NULL, 'application/json');
		return NULL;
	}
	//Get a session token
	public function buildToken($packageId)
	{
		$build = array(
			'packageId' => $packageId,
			'signerId' => 'Manager1'
		);
		$tokenJSON = json_encode($build);
		$token = json_decode($this->sendRequest($this->tokenAppend, $tokenJSON, NULL, 'application/json'), true);
		return $token;
	}
	//cURL function to send requests to eSignLive
	private function sendRequest($type, $json, $document, $contentType)
	{
		if (is_null($document) && is_null($contentType))
		{
			$postfields = array(
				"payload" => $json
			);
		}
		else if (is_null($document) && !is_null($contentType))
		{
			$postfields = $json;
		}
		else
		{
			$postfields = $document;
		}
		$headerOptions = array(
			'Authorization: Basic ' . $this->key,
			'Accept: application/json,application/zip,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
		);
		if (!is_null($contentType))
		{
			$headerOptions[] = "Content-Type: $contentType";
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->url . $type);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_FAILONERROR, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		if (!is_null($postfields))
		{
			curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
			if (!is_array($postfields))
			{
				$headerOptions[] = 'Content-Length: ' . strlen($postfields);
			}
		}
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);
		$response = curl_exec($ch);
		$err = curl_error($ch);
		curl_close($ch);
		
		if ($err)
		{
			return $err;
		}
		else
		{
			return $response;
		};
	}
	//cURL function to send requests to eSignLive
	public function sendGetRequest($type)
	{
		$headerOptions = array(
			'Content-Type: application/pdf',
			'Authorization: Basic '.$this->key
		);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this->url . $type);
		curl_setopt($ch, CURLOPT_FAILONERROR, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headerOptions);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$response = curl_exec($ch);
		$name       = time().'.pdf';
		$file 		= 'upload/filled/'.$name;
		$filename 	= 'filename.pdf';
		file_put_contents($file, $response);
		header('Content-type: application/pdf');
		header('Content-Disposition: inline; filename="' . $filename . '"');
		header('Content-Transfer-Encoding: binary');
		header('Content-Length: ' . filesize($file));
		header('Accept-Ranges: bytes');
		return $name;
		
	}
}?>
Reply to: how to add text field in pdf, while creating package
Monday, October 29, 2018 at 05:23am{ "roles": [ { "id": "Signer1", "type": "SIGNER", "signers": [ { "firstName": "John", "lastName": "Smith", "email": "[email protected]" } ], "name": "Signer1" } ], "documents": [ { "approvals": [ { "fields": [ { "type": "SIGNATURE", "extract": true, "subtype": "FULLNAME", "name": "signature1" }, { "type": "INPUT", "extract": true, "subtype": "TEXTFIELD", "name": "account_number" } ], "role": "Signer1" } ], "extract": true, "name": "Sample Contract" } ], "name": "Field Position Extraction Example", "status": "SENT" }Hope this could help! DuoReply to: how to add text field in pdf, while creating package
Tuesday, October 30, 2018 at 03:42amReply to: how to add text field in pdf, while creating package
Tuesday, October 30, 2018 at 08:57amReply to: how to add text field in pdf, while creating package
Tuesday, October 30, 2018 at 08:57amReply to: how to add text field in pdf, while creating package
Wednesday, October 31, 2018 at 01:55ampublic function buildDocument($packageId,$application_id) { $application = Application::find($application_id); $payment_term = PaymentTerm::where('application_id',$application->id)->first(); $director = unserialize($application->directors); $user = Auth::user(); $director_count = 1; $approvals = array(); $approvals[] = array ( 'fields' => array ( 0 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'name_of_account', ), 1 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'bsb_number', ), 2 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'account_number', ), 3 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'institution_name', ), 4 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'institution_address1', ), 5 => array ( 'type' => 'INPUT', 'extract' => true, 'subtype' => 'TEXTFIELD', 'name' => 'institution_address2', ), ), 'role' => 'Signer1', ); $build = array( 'fields' => array( array( 'value' => $application->entity_name, 'name' => 'customer_name', ) , array( 'value' => $application->address, 'name' => 'customer_address', ) , array( 'value' => $application->phone, 'name' => 'telephone', ) , array( 'value' => $user->company_name, 'name' => 'supplier_name', ) , array( 'value' => $user->address, 'name' => 'supplier_address', ) , array( 'value' => $user->state.', '.$user->pincode, 'name' => 'supplier_address2', ) , array( 'value' => '', 'name' => 'email', ) , array( 'value' => $application->abn_number, 'name' => 'abn_number', ) , array( 'value' => $payment_term->installment, 'name' => 'installment', ) , array( 'value' => $payment_term->term, 'name' => 'month', ) , array( 'value' => $user->document_fee, 'name' => 'handling_fee', ) ) , 'approvals' => $approvals, 'extract' => true, 'name' => 'GRENKE - EQUIPMENT LEASE AGREEMENT FOR BUSINESS PURPOSES', 'id' => 'contract' ); if(isset($director[0]['f_name'])){ //directors $build['fields'][] = array( 'value' => $director[0]['f_name'].' '.$director[0]['l_name'], 'name' => 'director_name_1', ); } if(isset($director[1]['f_name'])){ $director_count = 2; $build['fields'][] = array( 'value' => $director[1]['f_name'].' '.$director[1]['l_name'], 'name' => 'director_name_2', ); } //items list 1st foreach ($application->items as $key => $value) { if(($key+1) == 5){ break; } $build['fields'][] = array( 'value' => $value->description, 'name' => 'item_'.($key+1), ); $build['fields'][] = array( 'value' => $value->quantity, 'name' => 'qty_'.($key+1), ); } //items list 2nd full if(count($application->items) > 4){ foreach ($application->items as $key => $value) { $build['fields'][] = array( 'value' => $value->description, 'name' => 'item_1_'.($key+1), ); $build['fields'][] = array( 'value' => $value->manufacturer, 'name' => 'manufacturer_1_'.($key+1), ); $build['fields'][] = array( 'value' => $value->quantity, 'name' => 'qty_1_'.($key+1), ); } } //items list 3rd if(count($application->items) = 4){ foreach ($application->items as $key => $value) { $build['fields'][] = array( 'value' => $value->description, 'name' => 'item_2_'.($key+1), ); $build['fields'][] = array( 'value' => $value->manufacturer, 'name' => 'manufacturer_2_'.($key+1), ); $build['fields'][] = array( 'value' => $value->quantity, 'name' => 'qty_2_'.($key+1), ); } }else{ //enter message to first row $build['fields'][] = array( 'value' => "Please see appendix", 'name' => 'item_2_1', ); $build['fields'][] = array( 'value' => "/equipment schedule.", 'name' => 'item_2_2', ); } $documentJSON = json_encode($build); if($director_count == 2){ $postdata = "--" . $this->MULTIPART_BOUNDARY . "\r\n"; $postdata .= "Content-Disposition: form-data; name=\"file\"; filename=\"application_pdf_form_d_2.pdf\"\r\n"; $postdata .= "Content-Type: application/pdf" . "\r\n\r\n"; $postdata .= file_get_contents(asset('upload/application_pdf_form_d_2.pdf')); $postdata .= "\r\n\r\n"; $postdata .= "--" . $this->MULTIPART_BOUNDARY . "\r\n"; $postdata .= "Content-Disposition: form-data; name=\"payload\"\r\n\r\n"; $postdata .= $documentJSON; $postdata .= "\r\n\r\n"; $postdata .= "--" . $this->MULTIPART_BOUNDARY . "--\r\n"; }else{ $postdata = "--" . $this->MULTIPART_BOUNDARY . "\r\n"; $postdata .= "Content-Disposition: form-data; name=\"file\"; filename=\"application_pdf_form_d_1.pdf\"\r\n"; $postdata .= "Content-Type: application/pdf" . "\r\n\r\n"; $postdata .= file_get_contents(asset('upload/application_pdf_form_d_1.pdf')); $postdata .= "\r\n\r\n"; $postdata .= "--" . $this->MULTIPART_BOUNDARY . "\r\n"; $postdata .= "Content-Disposition: form-data; name=\"payload\"\r\n\r\n"; $postdata .= $documentJSON; $postdata .= "\r\n\r\n"; $postdata .= "--" . $this->MULTIPART_BOUNDARY . "--\r\n"; } $status = $this->sendRequest($this->packageAppend . $packageId . '/documents', $documentJSON, $postdata, 'multipart/form-data; boundary=' . $this->MULTIPART_BOUNDARY); return $status; }Reply to: how to add text field in pdf, while creating package
Wednesday, October 31, 2018 at 05:00am