troubleshooting Question

Command Acrobat to make JPEG from PDF using PHP

Avatar of andreyman3d2k
andreyman3d2k asked on
Web DevelopmentPHPAdobe Acrobat
2 Comments1 Solution477 ViewsLast Modified:
I have a script that involves using GhostScript to make a JPEG thumbnail of a PDF when an image gets uploaded to the site. I cannot get it to work.

I was thinking though that I might be able to accomplish this by using PHP to issue appropriate commands to Acrobat 9 Pro to make the thumbnail. How would I got about doing this, if it is possible?

Below is the PHP that calls up ghostscript and then generates the thumbnail (I think only the $cmd = ... is what needs to be changed to call Acrobat instead)

Can this be done, and if so, how? Thank you!

// pdf additions begin
		} elseif (strtolower(array_pop(explode('.', $filename))) == 'pdf'){
 
//Here is the call to Ghostscript:
 
			$cmd = "C:/Program Files/gs/gs8.70/bin/gswin32c.exe -sDEVICE=jpeg -dNOPAUSE  -dBATCH -sOutputFile='My Documents/xampp/htdocs/ProjectArchive/albums/edit/pdftmp.$filename.%d.jpg' 'My Documents/xampp/htdocs/ProjectArchive/$image'";
 
 
			exec ($cmd, $output, $retval);
 
 
			if ($retval) die("Error $retval on command '$cmd'");
 
			if ($dh = opendir("{$CONFIG['fullpath']}edit")) {
				while (($file = readdir($dh)) !== false) {
					if (strpos($file, 'pdftmp') === 0){
						$parts = explode('.', $file);
						$jpeg = array_pop($parts);
						$i = array_pop($parts);
						$pdf = array_pop($parts);
						array_shift($parts);
						$rawname = implode('.', $parts);
						$dest = "{$CONFIG['fullpath']}$filepath$rawname.$i.jpg";
						$src = "{$CONFIG['fullpath']}edit/$file";
						resize_image($src, $dest, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use']);
						unlink($src);
					}
			}
		$thumbname = "{$CONFIG['fullpath']}$filepath/{$CONFIG['thumb_pfx']}$rawname.jpg";
		resize_image("{$CONFIG['fullpath']}$filepath$rawname.1.jpg", $thumbname, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use']);
        closedir($dh);
    }
	// pdf additions end
ASKER CERTIFIED SOLUTION
innotionent

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros