Export pdf and send to the server instead of the client?

6 posts, 0 answers
  1. Jason
    Jason avatar
    12 posts
    Member since:
    Oct 2014

    Posted 26 Oct 2015 Link to this post

    I need to capture a multi page form in pdf format and then save it to the server with the record and not to the client. This is the code I wrote that send it to the client, how can I modify it to send it to the server instead

     

    root.options.set("pdf", {
    multiPage: 'true'
    });
    $('#formContainer .appPage').each(function (section) {
    kendo.drawing.drawDOM(this).then(function (group) {
    group.options.set("pdf", {
    margin: {
    left: "1cm",
    right: "1cm",
    top: "1cm",
    bottom: "1cm"
    }
    });
    root.append(group);
    });
    });

    kendo.drawing.pdf.saveAs(root, "App.pdf");

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 29 Oct 2015 Link to this post

    Hello Jason,

    Saving the files on the server is not supported out of the box, since Kendo UI is a client-side library. You can achieve the desired results by posting the dataURI to the server via Ajax request, then storing it there, either as a file or as a dataURI string.

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Wyatt
    Wyatt avatar
    22 posts
    Member since:
    Aug 2012

    Posted 04 Feb in reply to Alexander Popov Link to this post

    Hi,

     

    do you have a rough example of this method?

     

    Thanks

  5. Wyatt
    Wyatt avatar
    22 posts
    Member since:
    Aug 2012

    Posted 04 Feb in reply to Wyatt Link to this post

    posting went well.

     

                $.ajax({
                    type: "POST",
                    url: "/home/pdfpost",
                    processData: false,  // tell jQuery not to process the data
                    contentType: false,  // tell jQuery not to set contentType
                    data: '{ "imageData" : "' + data + '" }',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                });

     

     

    the problem is creating the pdf file from the datauri in the controller.  any clues how to do that?

  6. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 08 Feb Link to this post

    Hello,

    As mentioned previously, creating a PDF file on the server is not supported as Kendo UI is a client-side library. You could however, use third-party libraries that do that. Here is an example that you might find helpful:
    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  7. Wyatt
    Wyatt avatar
    22 posts
    Member since:
    Aug 2012

    Posted 11 Feb Link to this post

     

     found a way to do it..

    kendo.drawing.drawDOM($(".pdf-content"))
          .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) {
     
              $.ajax({
                  type: "POST",
                  url: publish + "/home/pdfpost",
                  processData: false// tell jQuery not to process the data
                  contentType: false// tell jQuery not to set contentType
                  data: '{ "imageData" : "' + data + '" ,"id": "' + self.customerGuid() + '"}',
                  contentType: 'application/json; charset=utf-8',
                  dataType: 'json',
              });
     
              
          });

     

    // controller (MVC) 

    imageData = imageData.Replace("data:application/pdf;base64,", "");
    byte[] bytes = Convert.FromBase64String(imageData);
     
    Stream stream = new MemoryStream(bytes);
     
    EmailMessage email = new EmailMessage(service);
     
    email.Attachments.AddFileAttachment("SALOR.pdf",stream);
Back to Top
Kendo UI is VS 2017 Ready