Automatically add '.pdf' extension and open resulting file when printing to PDF in Firefox
Emily Wong
When I print a webpage to PDF in Firefox, it saves the file but without the .pdf extension in the name. I have installed various add-ons but ended up with the same result.
I don't want to manually rename my files with the file manager.
Is there a setting somewhere to change this behaviour so that the file name is always suffixed with `.pdf'?
And how can I set it up to open the file with the default PDF viewer automatically after it got created?
13 Answers
You can just simply add the .pdf suffix to the file name you chose yourself.
On Linux systems, files are not judged by their extensions, but by their content or actually by the first few bytes of their content. That way it can determine with what applications to open a file without having to rely on the names. This might sound confusing for Windows users but works pretty well.
So as long as you only need that PDF document on your Ubuntu system, there's no need for an extension unless you want it. And if you want to open it on Windows, you could manually rename the file (e.g. with your Files manager nautilus) afterwards.
Or as I already said, just directly enter the full name including the .pdf extension into the print dialogue. It will even remember the name you used last (or default to mozilla.pdf, this probably depends on the version), so that you can just leave the extension there and overwrite the basename only.
Firefox comes with its own PDF printer, which works well, but a alternative is to use the CUPS PDF printer (I think part of the cups-pdf package). This will should work with all apps that can print by adding a extra printer which outputs a PDF file (by default on the desktop I think) - it also automatically adds a appropriate filename based on the title (e.g. Automatically_add___pdf__extension_and_open_resulting_file_when_.pdf)
For opening the file automatically, it may be possible by defining your printer which (using a script) converts the page a pdf (using GhostScript or another program), saves it and then opens the default PDF viewer. It should be possible to find out how add a printer by examing the files installed by the Cups PDF printer package, or perhaps by using Cups commands to a custom PPD file (see here)
The command in step 4 monitors your download folder by using a script (see step 2). The script checks the mimetype newly added files. If the file is a PDF, then a suffix is added, if necessary, and the file is opened.
Install the package inoticoming
sudo apt-get install inoticomingCreate wrapper script
handlePdfDownloadmkdir -p ~/bin nano ~/bin/handlePdfDownloadAdd the code below
#!/usr/bin/env bash FILE="$1" FOLDER="$2" if [ "$(mimetype -b "$FOLDER/$FILE")" != "application/pdf" ]; then exit 1 fi if [ "${FILE##*.}" != "pdf" ]; then mv "$FOLDER/$FILE" "$FOLDER/$FILE.pdf" fi xdg-open "$FOLDER/$FILE.pdf" exit 0Set the executable bit
chmod +x ~/bin/handlePdfDownloadWatch your
Downloadsfolderinoticoming ~/Downloads ~/bin/handlePdfDownload {} ~/Downloads \;