HOWTO: Remove password protection / encryption from PDFs

Wanted to share this for some time as others might face the same issue in Taiwan:

The government, banks and many companies in Taiwan love encrypted PDFs for some reason.

Mostly, one’s ARC-number / ID-number will be used as a password - however, there are exceptions: Sometimes, it’s the passport number - sometimes it’s a combination of an account number / birthday and other data.

For me, this caused lots of headaches as I wanted to archive those PDFs without remembering the specific password for each file (and over the years, many of those numbers will change…).

What finally worked for me was a simple open-source tool to remove the password protection without modifying the actual document (another way seems to be to print the PDF to another PDF - but this caused the size to increase in many cases for me):

(If you’re on Windows, go to releases and download the one ending in -msvc32.zip. Then, unzip to a location on your computer).

Then, you simply call the program

qpdf.exe --decrypt --password=%password% "%inputFile%" "%outputFile%"

And voilá - the password is gone!

With the help of ChatGPT, I created a small shell script which allows me to drag&drop the file I want to encrypt into it, enter the password - and the rest will be handled automatically (Assuming you unzipped the program to C:\Program Files (x86)\qpdf-11.9.1-msvc32) - save as unprotect_pdf.bat on your computer and then simply double-click:

@echo off
setlocal enabledelayedexpansion

:Start
:: Ask for the input file path
echo Please enter the full path to the PDF file (including the extension):
set /p inputFile=

:: Remove enclosing quotes if provided
set inputFile=%inputFile:"=%

:: Check if the file exists
if not exist "%inputFile%" (
    echo File does not exist. Please try again.
    echo.
    goto Start
)

:: Extract the directory and filename without extension
for %%F in ("%inputFile%") do (
    set inputDir=%%~dpF
    set inputFileName=%%~nF
)

:: Ask for the password
echo Please enter the password for the PDF file:
set /p password=

:: Set the output file path
set outputFile=%inputDir%!inputFileName!_unprotected.pdf

:: Run the qpdf command
"C:\Program Files (x86)\qpdf-11.9.1-msvc32\bin\qpdf.exe" --decrypt --password=%password% "%inputFile%" "%outputFile%"

:: Check the result
if %errorlevel% equ 0 (
    echo PDF password removed successfully.
    echo The unprotected file is saved at: "%outputFile%"
) else (
    echo Failed to remove the password. Please check the input file and password.
)

:: Loop back to the start
echo.
goto Start

Hope this helps someone!

2 Likes

I use: Solutions for all PDF problems - 100% free - PDF24

4 Likes

Really helpful guys.