<p>It return correct result. </p>

<pre><code>function getHTTPCode($url) {

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, true);   
    curl_setopt($ch, CURLOPT_NOBODY, true);   
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT,10);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
    $output = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $httpcode;
</code></pre>

<p>}</p>

<pre><code>$url = 'http://arxiv.org/pdf/1207.41021.pdf';
if(getHTTPCode($url)==200) {
 echo  'found';
} else {
 echo  'not found';
}
</code></pre>
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>