Solved

Converting PDF to Image via PHP

Posted on 2004-09-13
10
1,164 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 11

Accepted Solution

by:
shmert earned 500 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Microsoft Office Picture Manager has a Picture Shortcuts pane that shows a list with the Recently Browsed folders. While creating my video Micro Tutorial here at Experts Exchange showing How to Install Microsoft Office Picture Manager in Office 2013…

785 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