Export page as pdf and send it to email attachment

2 Answers 149 Views
Drawer
Babu
Top achievements
Rank 1
Iron
Iron
Iron
Babu asked on 01 Mar 2023, 04:25 AM

Hi,

 

I am trying to implement same way as ASP.NET Core PDF Export Key Features Demo | Telerik UI for ASP.NET Core

but Its exporting in client side but it's not going to controller. Don't know what mistake I am doing. Is there a way to send the pad to controller and send it to email attachment. Below is my code.


        $("#btnSubmit").on("click", function (e) {
            e.stopPropagation();
            e.preventDefault();
            var sigval = signature.value();
            $('#lblSearchError').text('');
            if (sigval === undefined || sigval === '') {
                $('#lblSearchError').text('*Signature field is required.');
            } else {
                var data = $("#submitForm").serializeArray();
                var obj = { name: 'signature', value: sigval };
                data.push(obj);

                // Convert the DOM element to a drawing using kendo.drawing.drawDOM
                kendo.drawing.drawDOM($("#mainContect"))
                .then(function (group) {
                    // Render the result as a PDF file
                    return kendo.drawing.exportPDF(group, {
                        paperSize: "auto",
                        margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" }
                    });
                })
                .done(function (data) {
                    // Save the PDF file
                    kendo.saveAs({
                        type: 'POST',
                        dataURI: data,
                        fileName: "Provider.pdf",
                        proxyURL: '@Url.Action("Submit", "Provider")'
                    });
                });
            }
        });

I tried proxyURL AND URL none of them worked. When I clicked on submit button it's just downloading the pdf file. But it not hitting controller.

and in controller 


        [HttpPost]
        public ActionResult Submit(string contentType, string base64, string fileName)
        {
            //if (!ModelState.IsValid)
            //{
            //    data.Id = 0;
            //    return Json(data, JsonRequestBehavior.AllowGet);
            //}

            //var providerData = portalServices.saveProviderData(data);
            //    return Json(providerData, JsonRequestBehavior.AllowGet);

            var fileContents = Convert.FromBase64String(base64);

            return File(fileContents, contentType, fileName);
        }

2 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 06 Mar 2023, 07:59 AM

Hi Babu,

You need to set the forceProxy parameter to true in the kendo.saveAs method:

kendo.saveAs({
    type: 'POST',
    dataURI: data,
    fileName: "Provider.pdf",
    forceProxy: true,
    proxyURL: '@Url.Action("Submit", "Provider")'
});

For more details on the parameters of the saveAs method, see the API: https://docs.telerik.com/kendo-ui/api/javascript/kendo/methods/saveas

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Babu
Top achievements
Rank 1
Iron
Iron
Iron
answered on 23 Jun 2023, 06:01 PM
I am trying to attach pdf file to email and send email notifications to users. Problem is when try to use kendo.saveAs its opening in another window .  If user browser is having pop up block, the email function is not working as it is not allowing open other window. Is there any way that i can do this in same window or any other option?
$.ajax({
                        type: "POST",
                        data: data,
                        url: "IUA/Submit",
                        success: function (result) {
                            if (result.Id !== 0) {
                                alert("Your application has completed the review phase and is confirmed complete. Your PIN will be " + result.Id + ". To complete your submission, please click the OK button below.");
                                $('#loading').hide();

                                kendo.drawing.drawDOM($("#mainDiv"))
                                    .then(function (group) {
                                        // Render the result as a PDF file
                                        return kendo.drawing.exportPDF(group, {
                                            paperSize: "auto",
                                            margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" }
                                        });
                                    })
                                    .done(function (data) {
                                        // Save the PDF file
                                        kendo.saveAs({
                                            type: 'POST',
                                            dataURI: data,
                                            fileName: "IUAEnrollment.pdf",
                                            proxyURL: '@Url.Action("SavePDF", "IUA")',
                                            forceProxy: true,
                                            proxyTarget: "_blank"
                                        });
                                        displayLoading("#formDiv", false);
                                        location.reload();
                                    });
                            } else if (result.IsDuplicateRec == true) {
                                $('#loading').hide();
                                $("#divDuplicate").show();
                                $("#captchaDiv").load(location.href + " #captchaDiv>*", "");
                            } else if (result.IsMVCCaptcha == false) {
                                $('label[for="lblCaptchaErr"]').show();
                                $("#captchaDiv").load(location.href + " #captchaDiv>*", "");
                                setTimeout(WaitUntilLoad, 6000);
                            }
                        },
                        error: function () {
                            $('#loading').hide();
                            alert("Error occured during the submission. Please contact helpdesk.");
                        }
                    });
Ivan Danchev
Telerik team
commented on 28 Jun 2023, 07:28 AM

Hi Babu,

I've opened a support ticket on your behalf: Ticket ID: 1614297

Expect a reply from a Support agent in the ticket.

Tags
Drawer
Asked by
Babu
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Ivan Danchev
Telerik team
Babu
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or