Search code examples
javascriptjsonformio

Print JSON response as PDF or Excel using JavaScript


Im using the Form.io (http://formio.github.io/formio.js/app/examples/customendpoint.html

    // Triggered when they click the submit button.
    form.on('submit', function(submission) {
      console.log(submission);
      alert('Submission sent to custom endpoint. See developer console.');
      return fetch('https://hookb.in/ZrRRbJBe', {
          body: JSON.stringify(submission),
          headers: {
            'content-type': 'application/json'
          },
          method: 'POST',
          mode: 'cors',
        })
        .then(response => {
          form.emit('submitDone', submission)
          response.json()
        })
    });
    });

and i'm getting the JSON response in the console log. I'm trying instead of putting it in the console log, i want to put the data in the PDF format. I used the code

<div class="entry">
            <h1>{{data.page1Text}}</h1>
            <div class="body">
              {{body}}
            </div>

But still its coming as the {{data.page1Text}} ,any ways i can use that JSON to put as the PDF format or put in the EXCEL ,rather than putting in the Console.


Solution

  • To show form data within the PDF output, you will need to use the Content component in your form, which you can then use the following to print your field data.

    <h1>{{ data.page1Text }}</h1>