PDA

View Full Version : Working with PDF files and PHP


smitho
01-17-2008, 02:22 AM
I've been doing some searching and to work with PDF files it seems there's a couple of extra bits that are needed.

I have a process where people can upload a PDF file and I would like to do 2 things once they do.

1. obtain the page size of the PDF.
2. create a thumbnail either as a jpg/png/gif

From what I can gather you need to have ImageMagic install and linked into the web sever so your php code will use the options to read page size.

To create thumbnails from PDF files ghostscript needs to be installed on the web server.

Has anyone tired to do either of the 2 process mentioned and if so how did you resolve them. If anyone has any suggestion or ideas they would be appreciated.

Cheers.

davidj
01-17-2008, 08:43 AM
1. obtain the page size of the PDF.


not sure what you want here as the document can be zoomed or expanded so the dimensions change. Do you mean file size


2. create a thumbnail either as a jpg/png/gif


is this to allow the creation of bling button which you click to download the file or is the thumb to be used to deliver a snapshot of the document?

Whats the reason behind this.

domedia
01-17-2008, 02:29 PM
From what I can gather you need to have ImageMagic install and linked into the web sever so your php code will use the options to read page size.
Alternatives are:
-GDLib
-FreeImage

smitho
01-17-2008, 10:14 PM
Thanks guys,

davidj

By page size I mean is the page A4 is it A3 etc. What are the dimensions.

The preview would be so that you can see what the pdf looks like before clicking on the pdf and opening it or saving it to a destination.

domedia

Will look into

-GDLib
-FreeImage

Cheers.

smitho
01-18-2008, 05:15 AM
OK I finally got ghostscript installed on my Mac (should of done on the PC just click the install.exe) and the PDF to jpg is working using this code I found.


$file1 = "/uploads/$justname.pdf";
$file2 = "/uploads/$justname.jpg";
$result1 = @exec("/usr/local/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=jpeg -sOutputFile=$file2 $file1 2>&1");
I looked a the GDLib domedia am I correct in saying this is part of the GD if you check phpinfo()?

Also looked at FreeImage but not sure how to make it work with php. will keep trying.