Solved

Converting PDF to Image via PHP

Posted on 2004-09-13
10
1,162 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 29
what is best version of php to use 6 46
Problem sending file attachments 8 23
Scope of $_SESSION 17 30
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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

867 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

17 Experts available now in Live!

Get 1:1 Help Now