1. Overview

Portable Document Format (PDF) documents are widely used to share and exchange information. This is due to the fact that they’re versatile, portable, and can be viewed on various devices without compromising the formatting or layout.

In this tutorial, we’ll explore how to create a blank PDF document from the command line. First, we’ll discuss how to use the ghostscript command to achieve this. Next, we’ll use mutool, another command that will help us complete this task.

We’ll primarily focus on the Debian and Ubuntu Linux distributions.

2. Using the ghostscript Command

ghostscript is a versatile command-line tool used for working with PostScript and PDF files. Therefore, we can use it to create a blank PDF document.

First, we need to install ghostscript on our system:

$ sudo apt install ghostscript

In the example above, we utilize apt, a command line tool that’s used to manage packages in Linux.

So, this installation enables us to invoke ghostscript with the help of the gs command. It follows a general syntax:

$ gs -o output_file_name.pdf -sDEVICE=pdfwrite -gpage_width x page_height -c "showpage"

The options above provide the gs command further instructions to help personalize the output.

Let’s review these options:

  • -o: specifies the output file name for the PDF document we want to create
  • output_file_name.pdf: defines the name of the output file we want to create. We can replace this with the desired name of our PDF file.
  • -sDEVICE=pdfwrite: this option tells ghostscript to create a PDF file
  • -gpage_width x page_height: used to set the page size and orientation of the PDF file by replacing page_width and page_height with the desired dimensions of our blank page
  • -c “showpage”: this option instructs ghostscript to create a blank page

Next, let’s navigate to the Documents/ directory. This is where we’ll save our blank PDF document:

$ cd Documents/

Once we’re in this directory, let’s go ahead and create a blank PDF document:

$ gs -o blank.pdf -sDEVICE=pdfwrite -g6120x7920 -c "showpage"

Here, we create a new PDF file named blank.pdf that contains a single blank page. Also, the -g6120x7920 option sets the page size to 8.5 inches by 11 inches.

In addition to creating a single blank page, we can also create a PDF document with multiple blank pages. To do this, we simply need to add more “showpage” parameters to the -c option:

$ gs -o blank.pdf -sDEVICE=pdfwrite -g6120x7920 -c "showpage" -c "showpage" -c "showpage"

The above command creates a new PDF document named blank.pdf containing three blank pages.

3. Using the mutool Command

mutool is a command-line tool for working with PDF files. In particular, we can use it to create, manipulate, and extract information from PDF files. In this case, we’ll use it to create a new blank PDF document.

Before we proceed, we need to install this tool:

$ sudo apt install mupdf-tools

This command helps to successfully install mutool from the mupdf-tools package.

Next, let’s take a look at the general syntax we’ll use to invoke mutool from the command line:

$ mutool create [options] output.pdf [input.pdf]

It contains these parameters:

  • mutool: the name of the command-line tool
  • create: this is the command we’re using to create the PDF document
  • [options]: refers to any additional options we may want to specify while creating the PDF document
  • output.pdf: the name of the output PDF file that we want to create
  • [input.pdf]: specifies an input PDF file that we want to use as a template for the new PDF document

Finally, let’s proceed with creating the document by using the syntax we discussed:

$ mutool create -o blank.pdf /dev/null

Using the instruction above, we’ve been able to create a blank PDF document named blank.pdf. To understand, the -o option specifies the name of the output file as blank.pdf. Moreover, we use /dev/null as the input file, which is a special file in Linux that discards all data written to it.

4. Conclusion

In this article, we discussed two approaches important for creating a blank PDF document in Linux.

We learned how to utilize ghostscript as well as the mutool command line tool to achieve this. We also explored some of the options to use with both commands to customize the output.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.