0
votes

I'd like to do something similar to Removing PDF password protection, knowing the password but in Windows. I have a folder with several PDFs that all have the same password, which I know. I would like to remove the password and overwrite the original files (don't worry, my data is a copy of another folder).

My thoughts are to use Autohotkey and create a script to open the file, paste the password, click enter, press Ctrl+P, click Print as PDF, save as the original file name, close Edge (which is what I'm using to open the PDFs), and then go to the next file in the folder.

I'm honestly not that familiar with AHK and would appreciate any help in what the code should be.

Thanks!

Edit: Here's some code I've tried but it doesn't seem to work.

^+q::
Loop %A_WorkingDir%\*.pdf
sleep 10000
Send, PASSWORD
sleep 2000
Send,  {Enter}
Send, ^p
Click 105,694
WinClose, A
Return
1
try "print to PDF"jsotola
Yes but I'm trying to do this on 2,000 files. I'd rather not do it manually.J-Knight

1 Answers

0
votes

When looping through files (using a files-loop as you have), it's not actually opening these but is giving you access to its OS-level properties, such as path, name, and system properties. You can use this information to open each one, using Run - something like, Run , %A_LoopFileLongPath%. Note that you may need to set Edge as your default PDF viewer if it isn't already.

Currently, your loop is only executing the line just beneath it, which is a 10-sec. sleep. You have 2,000 PDFs? That's about 5.5 hours of sleep before moving on. ;) If you want to execute more than one line, enclose it in braces { }, like so:

Loop , 1000
{
    ; stuff
}

From there, I would consider using WinWaitActive along with possibly ControlSend instead of Sleep and possibly Send. This will make your script more robust and may also take less time (assuming 10s is an upper bound). If at all possible, I would also discourage using clicks as these can sometimes be problematic (sometimes you have to send it multiple times for one click or locations might change). You can definitely make it work without these suggestions, it just might take more trial-and-error.

It may also be a good idea to build in a way to pause your script if needed, since this will likely take some time to do things to 2,000 files.

The help documentation is excellent and shows proper syntax and examples. I'd recommend consulting it for each of the commands.
https://www.autohotkey.com/docs/AutoHotkey.htm