samita
samita

Reputation: 175

how to send pdf from view page to controller in php?

i have created pdf using jsPDF plugin and can also download the pdf file and my question is how to send the generated pdf to an input of name post[attachment]

form to send

 <form method = "post" action="" enctype = "multipart/form-data">
                                  <input type = "hidden" name = "<?php echo Yii::$app->request->csrfParam; ?>" value = "<?php echo Yii::$app->request->csrfToken; ?>"/>
                                  <input type = "hidden" name ="post[attachment]"   id="email">
                                  <input type = "hidden" name = "post[email]" value="<?php echo $d['booker']['email'] ?>">

                               </form>
                   <a href="javascript:demoFromHTML()"> <button type = "submit" class = "btn btn-outline-secondary btn-preview noprint"  >Email</button></a>

This is my script code

<script>
   function demoFromHTML() {
      var pdf = new jsPDF('p', 'pt', 'letter');
      source = $('#content')[0];
      specialElementHandlers = {
         '#bypassme': function (element, renderer) {
            return true
         }
      };
      margins = {
         top: 80,
         bottom: 60,
         left: 40,
         width: 522
      };
      pdf.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, { // y coord
               'width': margins.width, // max width of content on PDF
               'elementHandlers': specialElementHandlers
            },
            function (dispose) {
               var pdfBase64 = pdf.output('datauristring');
            }, margins
      );
   }
</script>

Upvotes: 0

Views: 293

Answers (1)

Akshay Vanjare
Akshay Vanjare

Reputation: 655

As you have created pdf on client side, i.e. in browser, you need to make an ajax call or submit the form to send file to the server (eventually to controller).

Upvotes: 1

Related Questions