How to remove the password from a PDF file using Linux command line options

by time news

I get a lot of electronic bills (Utility, Phone, Internet, Mobile, Cable, etc.) in PDF format for my small business, and I need to send them to my accountant. However, all PDF files are password protected. I don’t want to share my account password with anyone just to open my invoices. Evince is a PDF document viewer capable of displaying password-protected files, but it cannot remove the password. How do I remove a password from all PDF files on Ubuntu or any other Linux distro in batch mode?

You can remove the password using various utilities on Linux. Use any of the following options:

  • pdf: a useful tool for manipulating PDF files.
  • qpdf: The qpdf program is used to convert a PDF file into another equivalent PDF file.
  • xpdf-utils: Portable Document Format (PDF) package: utilities like pdftops and ps2pdf.
  • print to file: use the Evince software itself.

How do I use pdftk to remove the password?

Type the following command apt-get/apt command to install pdftk (note that it will also install java, if you don’t like java just use another tool):

sudo [apt-get/yum o el comando de su instalación] install pdftk

Decrypt a PDF called input.pdf with YOUR password PASSWORD-HERE and create unencrypted output.pdf, enter:

pdf input.pdf output output.pdf user_pw YOUR-PASSWORD-HERE

O

pdf input.pdf output output.pdf user_pw YOUR-PASSWORD-HERE owner_pw YOUR-PASSWORD-HERE

O

pdf input.pdf output output.pdf input_pw YOUR-PASSWORD-HERE

Where:

  • input_pw password: Enter PDF owner passwords
  • user_pw password: Enter PDF user passwords
  • owner_pw password: Enter the PDF owner passwords the same as input_pw.

How do I use qpdf to remove the password?

Perhaps, it is the easiest tool to use…

Type the following apt command to install the qpdf:

sudo apt-get install qpdf

Decrypt a PDF named input.pdf with password YOUR-PASSWORD-HERE and create unencrypted output.pdf, enter:

qpdf –password=YOURPASSWORD-HERE decrypt entry.pdf output.pdf

How do I use xpdf-utils to remove the password?

Type the following command to install the qpdf:

sudo apt-get install xpdf-utils

First, decrypt a PDF and create a postscript file, enter:

pdftops -upw YOUR-PASSWORD-HERE input.pdf

You will get the input.ps file. This can be printed or opened under Linux itself. But, you can convert it back from a .ps (postscript) file to a PDF as follows:

ps2pdf input.ps

Note that the ps2pdf command is part of ghostscript and will be installed when you run xpdf-utils.

How do I use evince to remove the password?

Open a pdf file using evince, enter:

evince input.pdf

Enter your password. Once open, click File > Print > Select “Print to file” > Select “PDF” as the output format and click Print.

Writing a shell script is left as an exercise for the readers.

If you don’t know the password, use Ghostscript like this:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=desencriptado.pdf -c .setpdfwrite -f encriptado.pdf

Pin It

You may also like

Leave a Comment