Categories
Technology Tutorial Ubuntu

Advanced PDF Printing on Ubuntu

I travelled down a road that failed, but I learned some cool things about printing to PDF on Ubuntu that I think are worth logging and sharing for others.

1. Out-of-the-Box PDF Printing (in case you didn’t know)

In case you are new to ubuntu and didn’t know it, basic PDF printing is already installed and working perfectly. All you do is choose ‘print to file’ when you select your printer and PDFs are created. This might be all you need to know from this tutorial.

2. Converting with Ghostscript / ‘convert’ Command

This convert command is powerful. You can convert pretty much whatever image file to PDF. Probably you can convert other files, too. If you don’t believe me how powerful it is, just type man convert and check out the options…

A problem, however, is that it had a significant security issue in the past and so all rights to use the command are disabled by default. If you are running a server probably you should do your own research on the topic but if you are regular user like me you can probably follow the advice I found online to just remove the security policy file / rename it. Here is what I did and it removed all the permission errors I got while trying to run the command:

Move to the directory where the policy is: cd /etc/ImageMagick-6
Move the ‘policy.xml’ file while giving it the a new name (which ultimately just renames it): sudo mv policy.xml policy_disabled.xml

Now you can run the ‘convert’ command and send whatever it is to a pdf:

convert original_image_file.jpg output_pdf_file.pdf

3. Installing a ‘Virtual Printer’ and ‘Printing’ to it graphically

Install the thing: sudo apt install printer-driver-cups-pdf

As soon as it’s done you should be notified that a new ‘printer’ has been installed, just like it was a normal hardware printer. Now you can simply ‘print’ like you normally would to the printer called “PDF”. It will output the files to your home directory in the “PDF” folder.

4. Advanced printing with the command line using the Virtual Printer

Now that you have installed the printer-driver-cups-pdf virtual printer thing above, you now have a ‘fake printer’ in your computer and can now do ‘lpr printing’ in the commmand line. You can learn about what you can do with lpr here but instead what we’re going to do is simply direct the printing to the printer called “PDF”.

So whatever you can do with a regular printer, it seems you can do it now to PDF.

5. Other

There is also this thing which may be of value researching. I didn’t have time but it seems like there may be other value there ps2pdfwr. This is already installed with ubuntu. It takes postscript stuff and makes PDFs. You can type man ps2pdfwr in your terminal to learn more.

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *