10

How can I use other font weights (such as Book 300 for Open Sans) in my documents?

Adding Open Sans only allows me to use Normal 400, for example.

3 Answers 3

4

It looks like Google has recently added a feature to select a font weight. It appears as an arrow in the list of fonts, and clicking it reveals a menu of font weights: enter image description here

1

It appears that Google docs has very limited functionality for google web fonts right now. For each font you use, you only have the option of the bold weight or normal weight that was set for the web font you selected.

0

Now that Google Apps Script is implemented in Google Documents, it is possible to create font weights:

Code

// global
var app = DocumentApp.getUi();

function onOpen() {
   app.createMenu('Font').addItem('Set font size', 'fontSize')
     .addToUi();
 }

function fontSize() {
  // selected text
  var selection = DocumentApp.getActiveDocument().getSelection();  

  // create input box
  var fontSize = app.prompt('Add Font Size','Input Integer (> 0)'
    ,app.ButtonSet.OK).getResponseText();

  // check if value exists
  if(!fontSize || fontSize == 0) { 
    app.alert("Error","No input present", app.ButtonSet.OK);
    return;
  }

  // https://developers.google.com/apps-script/reference/document/selection
  var elements = selection.getSelectedElements();
  for (var i=0, iLen=elements.length; i<iLen; i++) {
    var element = elements[i];

    // Only modify elements that can be edited as text; 
    // skip images and other non-text elements.
    if (element.getElement().editAsText) {
      var text = element.getElement().editAsText();

      // Bold the selected part of the element, 
      // or the full element if it's completely selected.
      if (element.isPartial()) {
        text.setFontSize(element.getStartOffset(), 
          element.getEndOffsetInclusive(), parseInt(fontSize));
      } else {
        text.setFontSize(parseInt(fontSize));
      }
    }
  }  
}

Screenshot

enter image description here

Example

I've created an example file for you to play around with: Font Size

Reference

See the following answer for instructions on how to implement the script (works the same as in a Google Spreadsheet): Font Size in Google Spreadsheets

4
  • 4
    I believe he is asking for font weight, not font size.
    – bafromca
    Commented Sep 5, 2013 at 17:27
  • @bafromca I think you're right.
    – Jacob Jan
    Commented Sep 5, 2013 at 20:28
  • 1
    yes, and there’s only setBold and not setFontWeight, so no chance Commented May 21, 2015 at 12:19
  • You should probably remove this answer as it doesn't answer the question at all.
    – james-see
    Commented Feb 24, 2016 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.