title: Generate pdf from html file without showing on browser
body: <p>I want to generate a <code>pdf</code> file from <code>html</code> template which is not loaded in browser. The basic idea is to load <code>html</code> in some <code>javascript</code> variable and convert it to <code>canvas/pdf</code> without showing on browser.</p>
  
  <p>Right now I am doing this by adding a frame on currently opened page and then removing frame after successfully generating it's pdf. But this is showing some fluctuation on the screen and scrollbar.</p>
  
  <p><strong>Current Code:</strong></p>
  
  <pre><code>$http.get("static/templates/pdf-template.html")
              .then(function (response) {
                  var html_string = response.data;
                  var iframe = document.createElement('iframe');
                  iframe.style.width = '100%';
                  document.body.appendChild(iframe);
                  setTimeout(function () {
                      var iframedoc = iframe.contentDocument || iframe.contentWindow.document;
                      iframedoc.body.innerHTML = html_string;
  
                      var divHeight = iframedoc.body.scrollHeight;
                      var divWidth = iframedoc.body.scrollWidth;
                      var ratio = divHeight / divWidth;
  
                      html2canvas(iframedoc.body, {
                          onrendered: function (canvas) {
                              var pdf = new jsPDF();
                              var width = pdf.internal.pageSize.width;
                              var height = pdf.internal.pageSize.height;
                              height = ratio * width;
  
                              var imgData = canvas.toDataURL('image/jpeg', 1.0);
                              pdf.addImage(imgData, 'JPEG', 0, 0, width, height);
                              pdf.save('pdf');
                              document.body.removeChild(iframe);
                          }
                      });
                  }, 10);
              });
  </code></pre>
  
  <p>Please suggest solution without using <code>iframe</code>.</p>