Developer Resources

Tecxoft digital signatures can be integrated into an application using multiple different programming languages. Given below some code samples to send sign request in Java, .NET and PHP language.

Java .NET PHP


Java

Find Java api code on Github at https://github.com/tecxoft/java_api. tecxoft_request.jar file is required in classpath for this API.

import java.io.FileOutputStream;
import com.tecxoft.tips.api.TIPSSignRequest;

public class SignRequest {
    public static void main(String args[]){
    	try{
	    // initialize the class with userId and password
	    TIPSSignRequest request = new TIPSSignRequest("224488", "password"); 
	    // signed PDF file data received in byte array
		// byte[] data = request.sendSignRequest(byteArray);
		// byte[] data = request.sendSignRequest(fileObj); 
	    byte[] data = request.sendSignRequest("C:/folder/testFile.pdf");
	    // choose to write the file to file system
	    FileOutputStream fileOutputStream = null;
	    fileOutputStream = 
                new FileOutputStream("C:/folder/pdfFile"+"-java"+".pdf");
	    fileOutputStream.write(data);
	    fileOutputStream.close();
	    System.out.println("File written.");
    	}
    	catch (Exception e) {
	    e.printStackTrace();
	}
    }
}


Java

Find .NET API on GitHub at https://github.com/tecxoft/dotNet_api. Below C# code shows how to use it, TecxoftRequest.dll is required in reference to run this sample code.

using TecxoftRequest;
using System.IO;
using System;

public class TestSignRequest {

    public static void Main(){
	System.Console.WriteLine("Sending sign request..");
	// read file
	byte[] bytes = File.ReadAllBytes("C:\\files\\pdf_input.pdf");
	SignRequest req = new SignRequest("442266", "password");
	try{
	    Stream stream = req.sendSignRequest(bytes);
	    FileStream fileStream = new FileStream("C:\\files\\output\\pdf_output.pdf", 
                                            FileMode.Create, FileAccess.Write);
	    CopyStream(stream, fileStream);
	    fileStream.Close();	
	    System.Console.WriteLine("File written.");					
	}catch(Exception exp){
	    System.Console.WriteLine(exp.ToString());
	}
    }
  
    public static void CopyStream(Stream input, Stream output){
	byte[] buffer = new byte[32768];
	int read;
	    while ((read = input.Read(buffer, 0, buffer.Length)) > 0){
		output.Write (buffer, 0, read);
	    }
    }

}


PHP

PHP code doesnot require any additional PHP API or extension. For fopen() function to work, allow_url_fopen must be enabled in PHP.

<?php
        $fileObj = fopen("download/testFile.pdf", "r");
	$data = fread($fileObj, filesize("download/testFile.pdf") );

	$userId = "446622";
	$password = "password";
	
	$context_options = array (
		'http' => array (
		'method' => 'POST',
		'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
			. "Content-Length: " . strlen($data) . "\r\n"
			. "Content-Type: application/signing \r\nUSER_ID: ".$userId." \r\n"
			. "PASSWORD: ".$password." \r\n",
		'content' => $data
		)
	);

	$context = stream_context_create($context_options);
	$fpp = fopen("https://tips.tecxoft.com/online", 'r', false, $context);

	$contents = stream_get_contents($fpp);
	$meta = stream_get_meta_data($fpp);

	$headers = array( sizeof($meta['wrapper_data']) );
	$i = 0;
	foreach ( $meta['wrapper_data'] as $key => $value ) {
	    $temp = explode(":", $value);
		if( sizeof($temp) > 1 ){
			$headers[ trim($temp[0]) ] = trim($temp[1]);
		}
		else{
			$headers[ $i++ ] = trim($temp[0]);
		}
	}
	
	// for debugging purposes uncomment following code.
	//foreach( $headers as $k => $v ){
	//	echo $k.' - '.$v.'<br/>';
	//}
		
	if( isset($headers['RESPONSE_STATUS']) && $headers['RESPONSE_STATUS'] == "SUCCESS" ){
		$returnedFile = microtime();
		$returnedFile = str_replace(" ", "_", $returnedFile);
		$returnedFile = str_replace(".", "_", $returnedFile);
		$returnedFile = $returnedFile.".pdf";

		$fp = fopen('download/'.'r_'.$returnedFile, 'w');
		fwrite($fp, $contents);
		fclose($fp);
		echo 'Request Id: '.$headers['REQUEST_ID'].'<br/>';
		echo 'Content Length: '.$headers['Content-Length'].'<br/>';
		echo 'Message: '.$headers['MESSAGE'].'<br/>';
		echo 'File written.';
		
	}
	else{ // request failed.
		echo 'ERROR: '.$headers['ERROR_CODE'].' '.$headers['MESSAGE'];	
	}
?>


Top