Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:31:21+00:00 2026-05-23T22:31:21+00:00

I have installed Ghostscript from MacPorts, and am trying to invoke it from a

  • 0

I have installed Ghostscript from MacPorts, and am trying to invoke it from a PHP script to extract single page from a multi-page PDF file and then output it. My code looks like this:

<?php

$cmd = '/opt/local/bin/gs -sDEVICE=pdfwrite -dNOPAUSE \
    -dBATCH -dSAFER -dFirstPage=20 -dLastPage=20
    -sOutputFile=%stdout  "/path/to/input/pdf.pdf"';

// Will uncomment this when it works
// header("Content-Type: application/pdf");

putenv("GS_LIB=/opt/local/share/ghostscript/9.02/lib");
putenv("GS_FONTPATH=/opt/local/share/ghostscript/fonts");
putenv("TMPDIR=/tmp");

passthru($cmd);

When I hit this script in a web browser, I see:

GPL Ghostscript 9.02 (2011-03-30) Copyright (C) 2010 Artifex Software, Inc.
All rights reserved. This software comes with NO WARRANTY: see the file
PUBLIC for details. **** Unable to open the initial device, quitting.

The same command works from a shell.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:31:23+00:00Added an answer on May 23, 2026 at 10:31 pm

    The apache/webserver user likely does not have the permissions or the same environment variables. Perhaps try sudo, or make sure apache has proper permissions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a multi-page PDF file into a bunch of JPEGs,
I am working on creating thumbnail image from the first page of pdf file.
I have installed a package from .rpm file and it is stored in /opt
I am trying to get PHP to convert PDFs to JPGs. I have installed
I have the following script to take an uploaded PDF in PHP and call
I have ImageMagick, IIS 6, Ghostscript, and PHP 5.3.1 installed on a Windows Server
I have a file abc.ps on my desktop. I have installed Ghostscript 9.05 on
I have installed pyglet onto Mac OS X 10.7.4 using MacPorts. pyglet only works
I have installed xampp on Windows7(64bit).I want to work with PHP, Apache and MySql.
Hello I have a problem with compiling a ghostscript from ports in openbsd 4.7.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.