How to Convert a Document to PDF in Linux Ubuntu

Convert a document to PDF
Convert a document to PDF

Converting a document to PDF is a common task, and Ubuntu, being a versatile Linux distribution, offers several methods to achieve this.

Linux being such a flexible OS gives you many ways to accomplish any task – we’ll show you 5 ways to to turn regular documents into the popular PDF format. Whether you’re using a graphical interface or prefer the command line, Ubuntu has tools to help you convert various types of documents to PDF format.

Method 1: Using LibreOffice

ubuntu desktop
Ubuntu desktop

LibreOffice is the default office suite in Ubuntu, and it supports exporting documents directly to PDF.

  1. Open the Document: Launch LibreOffice Writer, Calc, or Impress, and open the document you want to convert.
  2. Export as PDF:
    • Go to the File menu and select Export As.
    • Click on Export as PDF.
  3. Configure PDF Options (Optional): A dialog box will appear where you can configure various PDF options such as image compression, password protection, and more.
  4. Save the PDF: After configuring the options, click Export. Choose the location where you want to save the PDF, name your file, and click Save.

Method 2: Using the Print to PDF Feature

Ubuntu includes a built-in “Print to PDF” feature that works with almost any application that has a print option.

  1. Open the Document: Open the document in any application that supports printing (e.g., LibreOffice, Gedit, or even a web browser).
  2. Print the Document:
    • Go to the File menu and select Print.
    • In the print dialog, choose Print to File instead of selecting a physical printer.
  3. Save as PDF:
    • In the Output format section, make sure PDF is selected.
    • Choose a location and name for your file, then click Print.

Your document will be saved as a PDF file in the location you specified.

Method 3: Using the Command Line with cups-pdf

For those who prefer using the terminal, you can install and use cups-pdf, a virtual printer that outputs PDFs.

1. Install cups-pdf:

  • Open the terminal (Ctrl + Alt + T).
  • Run the following command to install cups-pdf:
sudo apt-get install cups-pdf

2. Print to PDF:

  • Open the document in any application that supports printing.
  • Select Print from the File menu.
  • Choose PDF as the printer.
  • The document will be saved as a PDF in the ~/PDF directory by default.

Method 4: Using convert Command (for Images and Simple Documents)

If you have an image or a simple document, you can use the convert command from the ImageMagick package.

1. Install ImageMagick (if not already installed):

  • Open the terminal and run:
sudo apt-get install imagemagick

2. Convert the Document:

  • Navigate to the directory where your document is located.
  • Use the following command to convert your file to PDF:
convert inputfile outputfile.pdf

Replace inputfile with the name of your file and outputfile.pdf with the desired PDF filename.

Method 5: Using wkhtmltopdf for HTML to PDF Conversion

For converting HTML files or web pages to PDF, wkhtmltopdf is a powerful tool.

1. Install wkhtmltopdf:

  • Run the following command in the terminal:
sudo apt-get install wkhtmltopdf

2. Convert HTML to PDF:

  • Use the command:
wkhtmltopdf input.html output.pdf

Replace input.html with your HTML file or URL and output.pdf with the desired PDF filename.

Conclusion

Ubuntu offers multiple methods to convert documents to PDF, catering to different types of users – from those who prefer graphical interfaces to command-line enthusiasts.

Whether you’re converting text documents, images, or web pages, Ubuntu provides a tool that can get the job done efficiently.