A friend of mine got some PDF files infected with malware. He figured out that if he opens them on Ubuntu and prints them back to a file it removes the malware.
Anyone know if there is a way to script the opening, printing, and closing of a directory of PDF files?
This will do the job:
Firstly:
Install a PDF printer, run the following in the terminal:
Secondly:
In the terminal,
cd
into the directory containing your PDF files and run the following command:Done:
The printed files are located in your home directory under a directory called
PDF
.Important notice:
When you install the PDF printer in the first step above ( by default ) it is named PDF as the name that identifies the printer in the system and the command in the second step above should work fine with no errors.
However if that is not the case on your system or if you had to remove and add the printer again, the name of the printer might change and you will get an error like
lpr: No such file or directory
. To solve this you need to find the new name for your PDF printer. This is how to do it:Type this in the terminal and hit enter:
lpstat -s
You will see output like this:
device for CUPS-PDF-Printer: cups-pdf:/
Your printers name is now CUPS-PDF-Printer and you need to modify the command in the second step accordingly, like so:
find . -maxdepth 1 -type f -name '*.pdf' -exec lpr -P CUPS-PDF-Printer {} \;
Explanation - as requested by user3140225:
Contains the output of the
find
command.To see it in action:
Please run
find . -maxdepth 1 -type f -exec echo {} \;
from within a directory that contains some files in it.Then run
find . -maxdepth 1 -type f
from within the same directory.The output is the same.
Prevents the semicolon
;
after it from being interpreted as a shell punctuation which will prematurely terminate the command.Indicates the end of the argument part for
-exec
which is needed for it to work correctly.