<p>You may want to use <a href="http://php.net/manual/en/book.curl.php" rel="nofollow">curl</a> and check for a <code>200</code> <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html" rel="nofollow">http status code</a> , i.e.:</p>

<pre><code>&lt;?php

$url = 'http://arxiv.org/pdf/1207.41021.pdf';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);    // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true);    // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // we follow redirections
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);


if($httpcode == "200"){
    echo "file exist";
}else{
    echo "doesn't exist";
}
</code></pre>

<hr>

<p>Both pdf files return <code>403 Forbidden</code></p>

<blockquote>
  <p>The server understood the request, but is refusing to fulfill it.
  Authorization will not help and the request SHOULD NOT be repeated. If
  the request method was not HEAD and the server wishes to make public
  why the request has not been fulfilled, it SHOULD describe the reason
  for the refusal in the entity. If the server does not wish to make
  this information available to the client, the status code 404 (Not
  Found) can be used instead.</p>
</blockquote>
How to check whether pdf file exists?
<p>I am trying to check if pdf file exists in arXiv. There are two example</p>

<blockquote>
  <p><a href="http://arxiv.org/pdf/1207.41021.pdf" rel="nofollow noreferrer">arxiv.org/pdf/1207.4102.pdf</a> </p>
  
  <p><a href="http://arxiv.org/pdf/1207.41021.pdf" rel="nofollow noreferrer">arxiv.org/pdf/1207.41021.pdf</a></p>
</blockquote>

<p>The first is a pdf file and the second is not and returns an <a href="http://arxiv.org/pdf/1207.41021.pdf" rel="nofollow noreferrer">error page</a>.</p>

<p>Is there a way to check whether a url is pdf or not. I tried the answers in <a href="https://stackoverflow.com/questions/3646914/how-do-i-check-if-file-exists-in-jquery-or-javascript">How do I check if file exists in jQuery or JavaScript?</a> however none of them work and they return true (i.e. file exists) for both urls. Is there a way to find which url is pdf file in JavaScript/jQuery or even PHP? </p>

<p>Can this be solved using <a href="https://stackoverflow.com/questions/tagged/pdf.js">pdf.js</a>?</p>