title: Is there a way to print out a specific div of a webpage as pdf?
body: <p>I want to be able to print out a specific div as a PDF and JPG. I used the following code while running phantomjs: </p>
  
  <pre class="lang-js prettyprint-override"><code>var bb = page.evaluate(function() {
    return document.getElementsByTagName("fieldset")[7].getBoundingClientRect();
  });
  
  page.clipRect = {
    top: bb.top,
    left: bb.left,
    width: bb.width,
    height: bb.height
  };
  </code></pre>
  
  <p>This works fine for PNG but for PDF it just prints the whole page. Does anyone know why this is happening and how to solve it? If someone know of any other way to solve this, even something not involving phantomjs or some fronted solution, I'll be highly obliged if they share.</p>
  
  <p><strong>Edit</strong> I'm looking for a workaround to this problem, any frontend or backend solutions are acceptable.However some of the previous questions regarding this topic provide suggestions that involve html2canvas or jsPdf but those have problems with resolution so any other answers solutions will be appreciated.</p>