Add certificate at pdf and send via email

SOLVED
Hi Everybody
IS there the possibility of adding a certificate when generating a pdf invoice, and automatically sendind it by email? Right now we send pdf invoices by email, but I don't know if can add a certificate to pdf before. Has anyone encountered this problem?
  • +1
    verified answer

    Hello Sergi,

    So you already send pdf invoices through e-mail. I am assuming you are using workflow rules for that. Even if you are not using workflow rules, the same logic can be applied, which resumes to: Replace original PDF with Signed PDF.

    There is a little trick I usually do when I want to change pdf file names that are sent using workflow rules which can also work to sign the PDF before sending. This requires development skills.

    Basically in the workflow rule, there is a field for the attachments that usually has the value "GFILPATH" right? Here is the trick, this value is evaluated, so you can call a function (Funprog) that returns a filename!

    For example, if in the source file "YLIB" you have the Funprog "SIGN_PDF" you would replace GFILPATH for func YLIB.SIGN_PDF(GFILPATH) and would have the following code in YLIB:

    Funprog SIGN_PDF(ORIGINAL_FILE)
    Value Char ORIGINAL_FILE()
    
    Local Char FILE_TO_SIGN(GDIMFIC)
    # Sometimes the file name has a # to represent a number in case a print generates multiple files. Replace # with empty string
    FILE_TO_SIGN = CTRANS(ORIGINAL_FILE,"#","")
    
    If filinfo(FILE_TO_SIGN,7)>0 : # Make sure the file exists
        Local integer YSTAT
        # Copy file to a custom volume (here I am using the tmp folder)
        # You can change file name here, also... instead of <signed_pdf_<timestamp>.pdf>
        # Do not forget to dispose of the files after, if you have limited space or do not want to store sent pdfs
        Local Char PDF_TO_SIGN(GDIMFIC)
        PDF_TO_SIGN = filpath("tmp","","")+"\signed_pdf_"+num$(timestamp$)+".pdf"
        Call COPIE(FILE_TO_SIGN,PDF_TO_SIGN,YSTAT) From ORDSYS
    Endif
    
    #TODO
    Local Char SIGNED_PDF(GDIMFIC)
    # Sign PDF file in <PDF_TO_SIGN>
    SIGNED_PDF = "" : # ...
    
    # Return signed PDF
    End SIGNED_PDF



    To sign the PDF, refer to the following link:
    http://online-help.sageerpx3.com/erp/12/wp-static-content/static-pages/en_US/v7dev/api-guide_api-pdfsignature.html

    EDIT: Fixed file path logic in funprog example.

    Regards,
    Roberto Nascimento

  • 0 in reply to RobertoMSNascimento

    Hi Roberto!

    Thanks a lot for this code and example, you are a master! ClapClap