title: How to write javascript to reorder pages of a pdf document?
body: <p>I have a double-sided document as two separate pdf files — front-facing pages in one document and rear-facing pages in the second. </p>
  
  <pre><code>front.pdf
  rear.pdf
  </code></pre>
  
  <p>I have also combined them into a single document with all the pages but with all the front-facing pages before the rear-facing pages. The page ordering is of the form, <code>{1,3,5,7,...,[n],2,4,6,8,...,[n-1 OR n+1]}</code></p>
  
  <pre><code>all.pdf
  </code></pre>
  
  <p>I wish to write a simple javascript that can be run from inside Adobe Abrobat X Pro. Ideally, it would count the pages of the document <code>all.pdf</code>, handle both occasion when there are either an odd or even number of total pages and then reorder them such that they are in their original order:</p>
  
  <pre><code>page [1&gt;3&gt;4&gt;2] =&gt; page [1&gt;2&gt;3&gt;4]
  </code></pre>
  
  <p>The tiny leading code snippet above is from the answer by <strong>user171577</strong> on SuperUser in this question: <a href="https://superuser.com/questions/181596/software-that-merges-pdf-every-other-page">https://superuser.com/questions/181596/software-that-merges-pdf-every-other-page</a></p>