Reset All Font Sizes in Google Docs Using Google Apps Script

When working on a collaborative document, it’s easy for different font sizes and styles to accumulate, especially if multiple people have been editing. If you’re looking to restore a consistent, clean appearance throughout your Google Doc, resetting all text to the default font size and style can help bring uniformity. Instead of manually changing the font settings, you can use Google Apps Script to automate this task!

In this guide, we’ll create an Apps Script that resets the font size and style of all text elements in a Google Doc to their default values, making the document easier to read and visually cohesive.

Why Use Google Apps Script?

Google Apps Script is a powerful tool for automating repetitive tasks across Google Workspace apps. With a few lines of code, you can standardize text formatting, adjust styles, and perform batch operations. In this example, we’ll use Apps Script to ensure every text element in your Google Doc has a consistent font size and style.

Apps Script to Reset Font Sizes and Styles

Below is the code to create a Google Apps Script that resets the font size and style of all text in a document to the default values.

function resetFontSizeAndStyle() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const paragraphs = body.getParagraphs();

paragraphs.forEach(paragraph => {
const text = paragraph.editAsText();
if (text) {
// Reset font size and font family to default
text.setFontSize(null);
text.setFontFamily(null);
}
});
}

How the Script Works

  1. Access the Document: The script retrieves the active Google Doc and accesses its main body content.
  2. Loop Through Paragraphs: It iterates over each paragraph in the document.
  3. Reset Font Size and Style: For each paragraph, the script sets the font size and font family to null. Setting these attributes to null applies the default font size and font family configured in Google Docs, which typically follows the document’s default style.

Setting Up the Script

To use this script in Google Docs, follow these steps:

  1. Open Google Docs: Open the Google Doc where you want to reset font sizes and styles.
  2. Access Google Apps Script:
    • Go to Extensions > Apps Script to open the Apps Script editor in a new tab.
  3. Paste the Code: Copy and paste the code above into the editor.
  4. Save and Run:
    • Save your project with a relevant name, such as “Reset Font Sizes and Styles.”
    • Select resetFontSizeAndStyle from the dropdown and click the Run button.
  5. Authorize Permissions: When prompted, authorize the script to make changes to your Google Docs.

Example Use Case

Imagine your document contains text in various font sizes and styles due to editing changes. Here’s how it might look:

  • Heading in Arial, 16pt
  • Subheading in Verdana, 14pt
  • Body text in Times New Roman, 12pt

After running the script, all text in the document will revert to the default font style and size (e.g., Normal Text in Arial, 11pt if that’s your document’s default style).

Customizing the Script

If you want to apply a specific font size or font family instead of the default, you can modify the code as follows:

text.setFontSize(12); // Set all text to 12pt
text.setFontFamily("Arial"); // Set all text to Arial

This customization allows you to apply a standardized font size and style without relying on Google Docs’ default settings.

Conclusion

With this Google Apps Script, you can quickly reset all font sizes and styles in a Google Doc to their default values, ensuring a clean, cohesive appearance. This is especially useful for standardizing document formatting after extensive editing or collaboration.