How to generate a PDF file and send it via email

Follow steps below to generate a PDF file and send it via email on a mobile device:

Step 1: Generate the PDF file.

  • Method 1: Generate the PDF file by calling the SaveAs function of the DataWindow control, the DataWindowChild object, or the DataStore object.

    Syntax:

    saveas(filename, PDF!, colheading{, encoding})

    For example:

    dw_1.saveas("test.pdf", PDF!, True)

    Note:

    1. filename cannot be empty string or null value.

    2. The file path will be ignored, because the generated file is automatically saved to the %cachedir%/plugin/ directory (%cachedir% indicates the cache directory for the current mobile application). You can determine the cache directory by calling the AppeonGetCacheDir function, as shown in the code example below for step 2.

  • Method 2: Download an existing PDF file from the Appeon File Server to the mobile device.

    The PDF file will be automatically downloaded to the %cachedir%/plugin/ directory. You can determine the cache directory by calling the AppeonGetCacheDir function, as shown in the code example below for step 2.

    You can follow the instructions in Configuring and deploying Appeon File Server to install and configure the Appeon File Server and Uploading and downloading files to upload and download the PDF file from the Appeon File Server.

    Syntax:

    appeonfileservice lnv_ftp
    lnv_ftp = create appeonfileservice
    
    string ls_server
    integer li_port
    string ls_connectstring
    
    ...
    ls_connectstring = "username=appeon;password=appeon"
    
    ...
    ll_re = lnv_ftp.of_appeondownload ("test.pdf","") // download pdf file
    
    ...

Step 2: Send the PDF file.

  • Call the of_sendmail function of eon_mobile_awsex object to send the PDF file as attachment.

    Syntax:

    eon_mobile_awsex lnv_aws
    
    eon_mobile_str_mailcontent lstr_content
    string ls_recipient[]
    string ls_cc[]
    string ls_bcc[]
    string ls_attachmentfile[]
    integer li_re
    ...
    lnv_aws = create eon_mobile_awsex
    lstr_content.s_subject = "test mail"
    lstr_content.s_notetext = "This is a test mail"
    ls_recipient[1] = "support@appeon.com"
    ls_attachmentfile[1] = appeongetcachedir() + "/plugin/test.pdf"
    ...
    li_re = lnv_aws.of_sendmail (lstr_content, ls_recipient, ls_cc, ls_bcc, ls_attachmentfile)

Note: You should have an email account configured already on the mobile device to send the PDF file via email as attachment.