Solved

Converting PDF to Image via PHP

Posted on 2004-09-13
10
1,159 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

PaperPort 14.5 Patch 1 update is often not detected or downloaded automatically. This article provides direct download links to solve the problem for retail (non-bundled) versions of the Standard and Professional editions, as well as the Professiona…
This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
The viewer will learn how to dynamically set the form action using jQuery.
Microsoft Office Picture Manager is not included in Office 2013. This comes as quite a surprise to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This video expla…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now