cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Email with PDF Attachment in SAPUI5

903

Hi Experts,

We have used jsPDF in SAPUI5(UI5 Version 1.65.8) to generate the PDF document and we have binded the data into the jsPDF which is coming from oData results. We have generated the pdf successfully with the required fields.

Now our requirement is
1. To send an email with the pdf attachment which is generated using jsPDF without downloading the pdf.
2. Is there any option to store the generated pdf in the Z* tables of the SAP backend system.

Kindly provide your suggestion or valuable inputs.

Thanks & Regards,
Manimaran R.

View Entire Topic
thomas_arnesen
Explorer
0 Kudos

Hi there.

You can pass the PDF data via oData. In your SEGW entity, have a field, e.g. "Screenshot" that is of ABAP datatype STRING (Edm.String.with Precision/Scale/Max. length = 0).

Create the jsPDF document and add it to your oData object.:

var oPdfDoc = new jspdf("l", "pt", "a2"); // Whatever suits you
oPdfDoc.addHTML($("#viewCreate").get(0), { pagesplit: true },
    function () {
        // oNew is what you'll pass to the oData service.
        oNew.Screenshot = oPdfDoc.output("datauristring");
        oNew.Screenshot = oNew.Screenshot.replace("data:application/pdf;base64,", "");
        // Trigger the oData call using oNew
    }
);

In you oData service, in your DPC_EXT class (_CREATE_ENTITY for example) you convert the incoming (the oNew.Screenshot) to binary:

CALL FUNCTION 'SSFC_BASE64_DECODE'...

And, for example, add it to a workflow:

CALL FUNCTION 'SAP_WAPI_ATTACHMENT_ADD'...

Hope this points you in the right direction!

Regards,
Thomas