saveAs callback

8 posts, 1 answers
  1. Nisarg
    Nisarg avatar
    25 posts
    Member since:
    Jan 2015

    Posted 06 Feb 2017 Link to this post

    Hi there,

    I am using this method 'kendo.drawing.pdf.saveAs' to export pdf. Is there a callback or a promise in this method. Or is there a way to know when the download is accepted or canceled by the user?

    Thanks in advance!

  2. Eduardo Serra
    Admin
    Eduardo Serra avatar
    119 posts

    Posted 06 Feb 2017 Link to this post

    Hello Nisarg,

    We can use the method you describe as follows:

    drawing.pdf.saveAs(group, "filename.pdf", proxyUrl, callback);

    where the proxyUrl and callback arguments are optional; the callback will be invoked when the file has been successfully generated (generation could be asynchronous).

    I hope this helps!

    Regards,
    Eduardo Serra
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Nisarg
    Nisarg avatar
    25 posts
    Member since:
    Jan 2015

    Posted 06 Feb 2017 Link to this post

    the callback will be invoked when the file has been successfully generated (generation could be asynchronous).

    So you mean that I cannot be sure if the user has closed the download prompt?

    The reason that I need this callback is because I am exporting the pdf from a new tab, and when the download is done, I want to close the tab automatically.

    Will the callback satisfy this functionality?

  4. Answer
    Eduardo Serra
    Admin
    Eduardo Serra avatar
    119 posts

    Posted 07 Feb 2017 Link to this post

    Hello Nisarg,

    Although every application is different, I think from what you describe that the callback will satisfy your needs and allow you to know when to close the tab.

    If you find trouble during the implementation of this feature, reply back in a new forum thread and we will help you.

    Thank you.

    Regards,
    Eduardo Serra
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Cameron
    Cameron avatar
    2 posts
    Member since:
    Mar 2019

    Posted 17 Jun in reply to Eduardo Serra Link to this post

    Does not appear to work in the JQuery interface???
  6. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    729 posts

    Posted 19 Jun Link to this post

    Hi, Cameron,

    It seem to work in my test Dojo I created:

    https://dojo.telerik.com/@bubblemaster/eNUquyIl

    Please inspect it and let me know in case I have missed anything.

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Cameron
    Cameron avatar
    2 posts
    Member since:
    Mar 2019

    Posted 19 Jun in reply to Alex Hajigeorgieva Link to this post

    I was trying to do this type of thing.
    It generates a pdf but could not get the callback.

    function exportToPdf_WritingCriteria() {
    $(".highcharts-root").remove();
    kendo.drawing.drawDOM($(".reportDisplay_WritingCriteria"), {
    paperSize: ["230mm", "280mm"],
    scale: 0.5,
    margin: {
    left: "1cm",
    top: "2cm",
    right: "1cm",
    bottom: "0.5cm"
    },
    template: $("#page-template_WritingCriteria").html(),
    avoidLinks: true,
    repeatHeaders: true
    })
    .then(function (group) {
    // Render the result as a PDF file
    return kendo.drawing.exportPDF(group, {
    paperSize: "A4",
    landscape: false
    });
    })
    .done(function (data) {
    $("#exportbtn_WritingCriteria").prop('disabled', false);
    $("#chartArea_WritingCriteria").show();
    $("#exportPdfRunningSpan_WritingCriteria").hide();
    // Save the PDF file
    kendo.saveAs({
    dataURI: data,
    fileName: "WritingCriteria.pdf",
    proxyURL: "/Home/PdfExportSave",
    forceProxy: true
    });
    // Tried a few variations of this but did not run.
    //drawing.pdf.saveAs(data, "WritingCriteria.pdf", "/Home/PdfExportSave", function () {
    // alert("Drawing is complete")
    //});
    });
  8. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    729 posts

    Posted 21 Jun Link to this post

    Hi, Cameron,

    Thank you very much for sharing your code. Now I understand why the issue occurs.

    The current code uses the kendo.saveAs() method which does not have a callback while this thread is focused on the kendo.drawing.pdf.saveAs() method. To implement it in your code, you should replace the logic where the DOM is exported to PDF because the drawing method works with drawing groups, not dataURIs:

    https://dojo.telerik.com/@bubblemaster/EJIDIQUx

    Naturally, you may use the callback to execute the extra logic which shows/hides elements etc.

    Let me know if you have further questions or concerns.

    Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top