I need to read a PDF's page size rather cheaply, so my user can select specific pages (and load them in higher detail).
The only way I see to do this with Magick++ API is using the STL call readImages
. This does load in all the pages of the PDF as Magick::Images
, and gets quite expensive for large PDF documents (order of 50 pages takes about 15s on my machine.)
I did read a post on ImageMagick's forums that speaks about the ReadOptions
class (not documented at time of writing) you can pass to readImages
method to read lower density image, but this still takes too long. (About 10s). None of the other options on ReadOptions
really make a big difference with regards to speed.
Here is the code I have at the moment:
std::vector<Magick::Image> PDFImageList;
Magick::ReadOptions readOptions;
readOptions.density(Magick::Geometry(2,2));
readOptions.size(Magick::Geometry(1,1));
readOptions.depth(8);
// This call takes too long.
Magick::readImages(&PDFImageList, m_pathToPDFFile, readOptions);
int numberOfPages = PDFImageList.size();
I have also tried the Magick::Image.ping()
method, and can't find any data that it returns that relates to the page number.
Any other attribute or undocumented ImageMagick++ feature that I can try to get the page count cheaply?