Apps script for docs that clears font size for all paragraphs resets to the default keeps the bold and other styling

To create a Google Apps Script for Google Docs that clears the font size of all paragraphs and resets them to the default size while retaining other formatting such as bold, italics, etc., you can use the following script:

  1. Open your Google Doc.
  2. Go to Extensions > Apps Script.
  3. Delete any code in the script editor and replace it with the following:
function resetFontSizeKeepStyles() {
  var body = DocumentApp.getActiveDocument().getBody();
  var paragraphs = body.getParagraphs();
  var defaultSize = DocumentApp.getActiveDocument().getNamedStyle(DocumentApp.NamedStyleType.NORMAL_TEXT).getAttributes().FONT_SIZE;
  
  for (var i = 0; i < paragraphs.length; i++) {
    var child = paragraphs[i];
    var attributes = child.getAttributes();
    // Keep the text styles but reset the font size to the default
    attributes[DocumentApp.Attribute.FONT_SIZE] = defaultSize;
    child.setAttributes(attributes);
  }
}
  1. Save the script with a name, for example, ResetFontSize.
  2. Close the Apps Script window.
  3. To run the script, go back to your document, then go to Extensions > Macros > Manage macros, and then click on ResetFontSizeKeepStyles to run it.

This script iterates through all paragraphs in the document, resets their font size to the default while keeping other formatting attributes like bold, italic, underline, etc., intact. Note that the default size is determined based on the ‘Normal text’ style of the Google Doc. If your document uses a different standard size for normal text, you might need to manually adjust the defaultSize variable in the script.