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

  • Home
  • SEARCH
  • 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 8697923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:51+00:00 2026-06-13T01:37:51+00:00

I need to put a password protection to PDF files using ghostscript in php.

  • 0

I need to put a password protection to PDF files using ghostscript in php.

These files will be uploading to server using simple form (I don’t need any help with this), but they won’t have any protection at first. So I want to put password protection to them using exec function and ghostscript in it. But I couldn’t find anywhere what ghostscript query should be like.

For example, I have a PDF file called File.pdf. I upload it and then I need to put protection to it and call it File_protected.pdf.

I was trying to do it like this but ‘.ps’ file weights too much and there is no password in the final File_protected.pdf:

exec("gs -dNOPAUSE -dBATCH -sDEVICE=pswrite -sOutputFile=File.ps File.pdf");
exec("gs -dNOPAUSE -dBATCH -sPDFPassword=password -sDEVICE=pdfwrite -sOutputFile=File_protected.pdf File.ps");
  • 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-06-13T01:37:52+00:00Added an answer on June 13, 2026 at 1:37 am

    OK so firstly you don’t need to convert the file to PostScript. Ghostscript is perfectly capable of taking the PDF file as an input and producing a PDF file as an output, lots of people do this for many reasons.

    However, you need to be aware that if you do this, Ghostscript isn’t just ‘stamping’ the PDF file or something, it is fully interpreting it down to marking operations and then making a completely new PDF file which incorporates those marks. But if you were satisfied by converting to PostScript and back to PDF you should find this satisfactory, its actually better than doing that 2 step conversion.

    Secondly, there is no ‘PDFPassword’ switch for the pdfwrite device, which is why its having no effect. There are 2 switches: -sOwnerPassword and -sUserPassword. You may also want to supply the -dPermissions switch.

    You should read the PDF reference manual to glean the details but in short the Owner can do anything to the file, the User is limited to the Permissions (which is a bit field). If you don’t supply a User password then anyone can open the file (limited to Permissions) but you need to supply the Owner password to do anything which is not allowed by the Permissions. I suspect this is what you want to do but its up to you.

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

Sidebar

Related Questions

i am an Apache Illiterate person, and i need very simple password protection for
I need to put a anchor inside my li, using the same space as
I need to put following code in the constructor of my startup form. JohnKenedy.BusinessSQLEXPRInstaller
I need to login to one development server to put things on live server.
I have to put a password in my web.config and i need to encrypt
EDIT: All I need is render /devise/registrations/edit in /settings/password To do that put this
In PHP-script i need to update title, content fields. If I put @ into
I need to add basic password protection to an Open XML Wordprocessing document. I
I am using wordpress but I need to put a twitter @anywhere / login
I need to put whois data in a table like registrant, created date, expire

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.