?
Solved

Converting PDF to Image via PHP

Posted on 2004-09-13
10
Medium Priority
?
1,183 Views
Last Modified: 2013-12-02
I need to take a PDF and extract all pages of the document as seperate images via php. How do i go about doing this? (and if it's possible to descrease the resolution while doing so .. that would be great. The source files are 300 dpi and I really only need them 72 pdi for showing them on the screen.)

Dan
0
Comment
Question by:micamedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 11

Accepted Solution

by:
shmert earned 2000 total points
ID: 12046108
Use imagemagick and ghostscript libs.  Once you install them (the hard part) you just call imagemagick as an external script, something like

convert -scale 120x80 myfile.pdf converted.png
0
 
LVL 1

Author Comment

by:micamedia
ID: 12046393
do you have any links with information on how to install these and more detailed information on how to use it?

0
 
LVL 8

Expert Comment

by:inq123
ID: 12047340
Hi micamedia,

Any google search could dig it up (http://www.imagemagick.org).  I second shmert that convert's probably the best choice for the job.

Cheers!
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 1

Author Comment

by:micamedia
ID: 12048002
but i'm not clear on if this runs via php or via the shell. and if it's via the shell then i am just executing shell commands via phps exec command right?

The question that comes up is php executes via the user "nobody" will it have the correct access to read and write and access the imagemagik program?

Of course i will research it myself later.. but now i have to run.

Dan
0
 
LVL 1

Author Comment

by:micamedia
ID: 12048024
also am i going to need root access to install imagemagic? or can i just use the DL command to link it in PHP..

I'll check it out soon. Just looked at the web site seems that it does interface directly with php, but i'm not sure if all the commands are avaibalbe via php.

Still shouldn't be to hard to run a shell command if the nobody user can do so.
0
 
LVL 8

Expert Comment

by:inq123
ID: 12048667
>but i'm not clear on if this runs via php or via the shell. and if it's via the shell then i am just executing shell commands via phps exec command right?

Yes.

>The question that comes up is php executes via the user "nobody" will it have the correct access to read and write and access the imagemagik program?

You'd have to chmod 0777 the directory where you intend to have images written

>also am i going to need root access to install imagemagic? or can i just use the DL command to link it in PHP..

No, you can install it to your directory.  It works fine this way too.

BTW, shmert seems to like using imagemagick (well I do too), but I think for your other question GD would do just fine and it's easy to use php API to do it.
0
 
LVL 1

Author Comment

by:micamedia
ID: 12050606
can GD convert PDF to jpg/gif?
0
 
LVL 11

Expert Comment

by:shmert
ID: 12054943
no, GD can't read PDFs.  ImageMagick needs the ghostscript lib to read/write PDFs.

You'll want to install both of these libs, and make sure ImageMagick can locate the ghostscript libs when called from the shell (without PHP, just for testing).  Just run the command above,

convert -scale 120x80 myfile.pdf converted.png

Once this works, you'll do the same thing from php, using exec, but specify the full path to the imagemagick binary when you call it from PHP:

exec('/usr/local/bin/convert -scale 120x80 myfile.pdf converted.png');

As far as permissions, 'nobody' only needs permission to execute the 'convert' command (which is by default executable for anyone), and the permission to write to the target directory.

What platform are you on?
0
 
LVL 1

Author Comment

by:micamedia
ID: 12061030
freebsd 4.8
0
 
LVL 8

Expert Comment

by:inq123
ID: 12064801
>but I think for your other question GD would do just fine and it's easy to use php API to do it.

I meant that for your other question "image zoom and pan" or something like that GD is just fine and should be better, without the hassle of installing imagemagick.  For imagemagick PDF on freebsd just search for their ports.  They have to be there.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question