title: Making PHP curl request to Download PDF using API url
body: <p>The following url will download a PDF of any given url if it's run on browser directly. 
  <a href="http://htmltopdfapi.com/querybuilder/api.php?url=http%3A%2F%2Fwww.google.com%2F" rel="nofollow">http://htmltopdfapi.com/querybuilder/api.php?url=http%3A%2F%2Fwww.google.com%2F</a></p>
  
  <p>I need to download the file using curl within my server itself. </p>
  
  <p>I am using CURL request to do this. </p>
  
  <pre><code>$CurlConnect = curl_init();
  $link = urlencode("https://www.google.com");
  $source = "http://htmltopdfapi.com/querybuilder/api.php?url=$link";
  curl_setopt($CurlConnect, CURLOPT_URL, $source);
  curl_setopt($CurlConnect, CURLOPT_HEADER, true);
  curl_setopt($CurlConnect, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt($CurlConnect, CURLOPT_NOBODY, true);
  curl_setopt($CurlConnect, CURLOPT_TIMEOUT, 10);
  curl_setopt($CurlConnect, CURLOPT_SSLVERSION,3);
  $Result = curl_exec($CurlConnect);
  header('Cache-Control: public'); 
  header('Content-type: application/pdf');
  header('Content-Disposition: attachment; filename="new.pdf"');
  header('Content-Length: '.strlen($Result));
  echo $Result;
  </code></pre>
  
  <p>The above code downloads the pdf, but the pdf is corrupted, How to make it work? </p>