Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Nowadays documents are no longer being manually signed. With the advent of digital signatures, documents are being signed digitally and shared over the internet. A lot of eSignature providers are now available in the market and they provide an interface for sending and signing documents online and work with the appropriate Certificate Authorities to provide trusted digital certificates. Most of the invoices shared online are being digitally signed and hence in order to automate invoice validation or Purchase order matching, one has to verify the authenticity of these digital signatures.

For one of my recent Proof of Concept for a customer, the use case was to download all invoices from a portal and to validate the data extracted from the invoice with the contents in the Ariba screen. We used the SAP AI Business Service Document Information Extraction and SAP Intelligent Robotic Process Automation to automate this usecase. There are a lot of tutorials on how to download invoices and on how to extract text from pdfs or images using Document Information Extraction and SAP Intelligent Robotic Process. I have listed them under references.

As part of the usecase, the customer also wanted to check if the invoice contained any digital signatures. In order to do this, we could use any one of the several providers available in the market. For this PoC, we agreed to use DocuSign API.


The steps to follow to check if an invoice contains a digital signature using DocuSign API are shown below:


  • Check if the given invoice is a pdf or an image. If it is an image, we convert it into a pdf and proceed directly to data extraction as it won’t contain a digital signature. If the invoice is a pdf, we proceed to step 2.


The code to convert an image to pdf is:

 
var command = 'img2pdf ' + jpgFile + ' -o ' + pdfFile;
var res = ctx.exec(command, 120);

              For this, the img2pdf library has to be installed on the machine.

 

  • Convert the pdf into base64 encoding
    var files = ctx.fso.folder.getFileCollection(ctx.options.path.log + "\\Invoices\\");
    var file_1 = files.item( );
    var fname = file_1.Path;
    var fle = ctx.fso.file.read(fname, e.file.encoding.Binary);
    rootData.txt64 = ctx.pdf._binBase64Encode(fle);



             

  • Prepare the data that has to be passed to the DocuSign API
    var data = {
    "bytes":rootData.txt64
    "mimeType":{
    "mimeTypeString":"pdf"
    }
    }​



                    


  • Call the DocuSign API and verify if the pdf has atleast one digital signature.
    ctx.ajax.call({
    url: 'https://validator.docusign.com/api/v1/rest/validation/validateSignature',
    method: e.ajax.method.post,
    data : data,
    contentType: e.ajax.content.json,
    success: function(res, status, xhr) {
    var signCount = res['signaturesReports']['simpleReport']['signaturesCount']
    ctx.log("Valid signature count :"+signCount);
    if(parseInt(signCount)>=1){
    ctx.log("Digital Signature verified");
    } else {
    ctx.log("digital signature not found");
    }
    sc.endStep();
    return;
    },
    error: function(xhr, error, statusText) {
    throw new Error('Cannot upload document (ajax call) (' + xhr.responseText + ')');
    }
    });​



                       

This project has been executed using SAP Intelligent Robotic Process Automation and the video recording of the DocuSign API workflow is shown below.



 

Feel free to reach out to me for any doubts on this scenario.

 

References:


As listed in the blog post, please find below a few blog posts on how to download email attachments and extract data from images and files using open source or custom built optical character recognition libraries or SAP AI Business Service Document Information Extraction.

  1. https://blogs.sap.com/2021/01/06/sap-intelligent-rpa-filter-email-attachments/

  2. https://blogs.sap.com/2020/02/23/how-to-build-custom-ocr-in-sap-rpa/

  3. https://blogs.sap.com/2020/05/12/combining-document-information-extraction-and-intelligent-rpa-to-au...


 
3 Comments