How to Automatically Add a Watermark to Multiple Google Docs Using Apps Script

Adding a watermark to a single Google Document is a straightforward process using the built-in Insert menu. However, if you are a manager or educator who needs to stamp “CONFIDENTIAL” or “DRAFT” across dozens or hundreds of files in a shared folder, doing it manually is an incredible waste of time. By utilizing Google Apps Script, you can automate this repetitive task and apply a uniform watermark to every document in a specific Google Drive folder simultaneously.

Preparing Your Google Drive Folder

Before executing the script, it is highly recommended to place all the documents you wish to watermark into a single, dedicated Google Drive folder. This allows the script to target the files cleanly without accidentally watermarking unrelated documents.

  1. Open Google Drive.
  2. Create a new folder and move all the target Google Docs into it.
  3. Look at the URL in your browser’s address bar. It will look something like https://drive.google.com/drive/folders/1A2b3C4d5E6f7G8h9I0j?usp=sharing.
  4. Copy the random string of characters after folders/ and before the question mark. This is your Folder ID.

Creating the Apps Script

We will write a custom Apps Script that iterates through the folder and modifies the header of each document to include a large, semi-transparent text watermark.

  1. Open a new tab and navigate to script.google.com.
  2. Click on New Project in the top left corner.
  3. Delete any default code in the editor and paste the following script:
    function batchAddWatermark() {
      var folderId = 'YOUR_FOLDER_ID_HERE';
      var folder = DriveApp.getFolderById(folderId);
      var files = folder.getFilesByType(MimeType.GOOGLE_DOCS);
      
      var watermarkText = "CONFIDENTIAL";
      
      while (files.hasNext()) {
        var file = files.next();
        var doc = DocumentApp.openById(file.getId());
        
        // Access or create the document header
        var header = doc.getHeader();
        if (!header) {
          header = doc.addHeader();
        }
        
        // Clear existing header content to prevent overlapping
        header.clear();
        
        // Add the watermark paragraph
        var paragraph = header.appendParagraph(watermarkText);
        
        // Style the watermark
        paragraph.setAttributes({
          [DocumentApp.Attribute.FONT_SIZE]: 72,
          [DocumentApp.Attribute.FOREGROUND_COLOR]: '#e0e0e0',
          [DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]: DocumentApp.HorizontalAlignment.CENTER,
          [DocumentApp.Attribute.BOLD]: true
        });
        
        doc.saveAndClose();
      }
    }
  4. Replace YOUR_FOLDER_ID_HERE with the Folder ID you copied earlier. Keep the single quotes around the ID.
  5. If you prefer a different watermark, change CONFIDENTIAL to your desired text.

Executing the Script

With the script written, you are ready to process your documents.

  1. Click the Save icon (floppy disk) in the toolbar.
  2. Click the Run button at the top of the editor.
  3. Google will prompt you with an “Authorization required” pop-up. Click Review permissions.
  4. Select your Google account and click Allow to grant the script access to your Google Drive files. (If warned that the app isn’t verified, click Advanced, then click Go to project).

The script will execute silently. Depending on how many files are in the folder, it may take a few moments. Once the execution log says “Execution completed,” open any document in your target folder, and you will see your large, grey watermark spanning the top of the page across all files.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.