alphagov/whitehall — pull request #1458 by vinayvinay (2014-05-06 10:47:43+00:00)
Title: Use imagemagick for counting pages in PDF uploads

https://www.pivotaltracker.com/story/show/68617050

PDFInfo was calculating a few other things as well
when we only needed the count of pages. This was
causing this process to be extremely slow (> 50s)
with some PDFs which had a lot of heavy images,
causing request timeouts.

We have Imagemagick installed on backend boxes to
resize the image uploads. Might as well use the
same tool to just count the number of pages in
the PDF, also speeds up the process multiple
times:

```
$ time identify -format %n ../business_plan_201213.pdf
25

real 0m4.252s
user 0m4.160s
sys 0m0.080s

$ time pdfinfo ../business_plan_201213.pdf
Creator: Adobe InDesign CS3 (5.0)
Producer: Adobe PDF Library 8.0
CreationDate: Tue Apr 17 11:08:59 2012
ModDate: Tue Apr 17 11:09:58 2012
Tagged: no
Pages: 25
Encrypted: no
Page size: 841.89 x 595.276 pts (A4)
File size: 4751247 bytes
Optimized: no
PDF version: 1.5

real 0m53.529s
user 0m44.923s
sys 0m8.217s
```