Page 1 of 1
Read one page from pdf
Posted: 2014-03-02T05:25:23-07:00
by antake
Hello!
I need to read a pdf document page by page because it is very large.
Can you please help me with it?
Sorry for such a simple question, I'm new to magick and can't find any good sources about it.
Re: Read one page from pdf
Posted: 2014-03-02T06:09:36-07:00
by magick
Just add [0] to your filename, that reads only the first page of a PDF document (.e.g page.pdf[0]).
Re: Read one page from pdf
Posted: 2014-03-02T10:10:10-07:00
by antake
Thank you but it seems I don't understand something.
Code: Select all
std::string documentPath = "doc.pdf[0]";
MagickCore::ImageInfo *imageInfo = MagickCore::CloneImageInfo(0);
documentPath.copy(imageInfo->filename, MaxTextExtent - 1);
imageInfo->filename[documentPath.length()] = 0;
MagickCore::ExceptionInfo exceptionInfo;
MagickCore::GetExceptionInfo(&exceptionInfo);
MagickCore::Image *imagesP = MagickCore::ReadImage(imageInfo, &exceptionInfo);
This code does not work. What wrong am I doing?
Re: Read one page from pdf
Posted: 2014-03-02T23:38:58-07:00
by antake
It works! Thank you very much!
Re: Read one page from pdf
Posted: 2014-03-03T00:46:13-07:00
by antake
And one more question.
As it seems to me I can read a range of pages adding [0-10] to the filename. But how can I extract single pages from the Image?
Re: Read one page from pdf
Posted: 2014-03-03T04:30:25-07:00
by magick
Append [0] to read the first page, or [1] to read the second, etc.
Re: Read one page from pdf
Posted: 2016-10-30T06:18:37-07:00
by randomstuff
what if that doesn't work? i am getting "unable to read file" message when trying to access a specific page like that on my server:(
what imagemagick verrsion introduced this?
edit: it seems my php imagemagick wrapper doesn't want to read no pdf file, not just a specific page. it seems that gs is located in /usr/bin as it should, i don't know how to debug this
Re: Read one page from pdf
Posted: 2016-10-30T07:43:42-07:00
by Bonzo
What command are you using?
Re: Read one page from pdf
Posted: 2016-10-30T10:59:08-07:00
by fmw42
Please do not add onto an old post in the future. Please start a new topic. What is your IM version and platform? What is your exact command.
Re: Read one page from pdf
Posted: 2016-10-31T05:31:16-07:00
by randomstuff
'i am sorry, i thought it would be better for google search results (i found this thread by googling my problem)
i am using php wrapper command
Code: Select all
$imagick = new Imagick();
$imagick->readImage('path_to_pdf/pdf.pdf');
Re: Read one page from pdf
Posted: 2016-10-31T09:45:00-07:00
by fmw42
You won't get much proper help if you do not answer the questions asked above.
Try
Code: Select all
$imagick = new Imagick();
$imagick->readImage('path_to_pdf/pdf.pdf[0]');
To get the first page, use [1] to get the second page, etc.
Re: Read one page from pdf
Posted: 2016-10-31T10:00:20-07:00
by snibgo
randomstuff wrote:it seems my php imagemagick wrapper doesn't want to read no pdf file
The problem is probably that PHP can't find Ghostscript. See many threads on this. The fix is to edit delegates.xml to add the full path to Ghostscript.