title: Send pdf file from PHP to JS by ajax
body: <p>My requirement is that I want to download the file hoisted in some other server from client . For this I making ajax call from js to PHP to fetch file , In php code I use below code to write pdf file:</p>
  
  <pre><code>  $fileContents =  file_get_contents("filepath.pdf");
    return $fileContents;
  </code></pre>
  
  <p>when I check the success Callback of ajax call , I get below information :</p>
  
  <pre><code>&gt; %PDF-1.3
  3 0 obj
  &lt;&lt;/Type /Page
  /Parent 1 0 R
  /Resources 2 0 R
  /MediaBox [0 0 595.28 841.89]
  /Contents 4 0 R&gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;/Length 5494&gt;&gt;
  stream
  0.20 w
  0 G
  BT
  /F1 12 Tf
  13.799999999999999 TL
  0 g
  20.00 811.89 Td
  ....
  here some more data ...
   31
  0000000000 65535 f 
  0000035549 00000 n 
  0000036792 00000 n 
  0000000009 00000 n 
  0000000117 00000 n 
  0000005661 00000 n 
  0000005769 00000 n 
  0000011156 00000 n 
  0000011264 00000 n 
  0000016681 00000 n 
  0000016790 00000 n 
  0000022174 00000 n 
  0000022284 00000 n 
  0000027620 00000 n 
  0000027730 00000 n 
  0000033220 00000 n 
  0000033330 00000 n 
  0000035645 00000 n 
  0000035736 00000 n 
  0000035832 00000 n 
  0000035931 00000 n 
  0000036034 00000 n 
  0000036123 00000 n 
  0000036217 00000 n 
  0000036314 00000 n 
  0000036415 00000 n 
  0000036508 00000 n 
  0000036600 00000 n 
  0000036694 00000 n 
  0000037021 00000 n 
  0000037326 00000 n 
  trailer
  &lt;&lt;
  /Size 31
  /Root 30 0 R
  /Info 29 0 R
  &gt;&gt;
  startxref
  37430
  %%EOF
  </code></pre>
  
  <p>How can I parse this data to generate a download file.  I cannot directly provide the URL of pdf file to download due to security concerns , so need to fetch the file via PHP then to create pdf by using jsPDF library.
  Issue is in parsing this data or how can we get content of pdf from php and send it to js. </p>