Read one page from pdf

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
antake
Posts: 7
Joined: 2014-03-02T03:58:12-07:00
Authentication code: 6789

Read one page from pdf

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read one page from pdf

Post by magick »

Just add [0] to your filename, that reads only the first page of a PDF document (.e.g page.pdf[0]).
antake
Posts: 7
Joined: 2014-03-02T03:58:12-07:00
Authentication code: 6789

Re: Read one page from pdf

Post 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?
antake
Posts: 7
Joined: 2014-03-02T03:58:12-07:00
Authentication code: 6789

Re: Read one page from pdf

Post by antake »

It works! Thank you very much!
antake
Posts: 7
Joined: 2014-03-02T03:58:12-07:00
Authentication code: 6789

Re: Read one page from pdf

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read one page from pdf

Post by magick »

Append [0] to read the first page, or [1] to read the second, etc.
randomstuff
Posts: 2
Joined: 2016-10-30T06:16:58-07:00
Authentication code: 1151

Re: Read one page from pdf

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Read one page from pdf

Post by Bonzo »

What command are you using?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Read one page from pdf

Post 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.
randomstuff
Posts: 2
Joined: 2016-10-30T06:16:58-07:00
Authentication code: 1151

Re: Read one page from pdf

Post 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');
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Read one page from pdf

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read one page from pdf

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply