Google Apps Script paragraph line spacing won't accept values below 1.0

I’m working on a Google Apps Script that creates a document with two text lines that should be positioned very close to each other. When I manually adjust line spacing in Google Docs through the UI, I can set custom spacing to 0.5 or similar small values and it works fine.

However, when I try to do this programmatically with Apps Script, any value less than 1.0 gets ignored and defaults back to standard spacing. Values above 1.0 work perfectly.

Here’s my test code:

let document = DocumentApp.openByUrl("GOOGLE_DOC_URL").getBody()
let paragraph = document.appendParagraph("")
paragraph.setAlignment(DocumentApp.HorizontalAlignment.CENTER)
paragraph.setLineSpacing(0.5)

let firstText = paragraph.appendText(`First line\r`)
firstText.setFontSize(28)

let secondText = paragraph.appendText("second line")
secondText.setFontFamily("Arial")
secondText.setFontSize(12)
console.log(paragraph.getLineSpacing())

The console shows 0.5 as expected, but the actual document always displays with 1.0 spacing. If I change the value to something like 1.5, it applies correctly.

Is this a known limitation or am I missing something?

Had this same problem six months ago building an automated report generator. Google Apps Script accepts lower line spacing numbers through the API, but it enforces minimum values anyway. I fixed it by making separate paragraphs instead of line breaks in one paragraph, then tweaked spacing between paragraphs with setParagraphHeading or custom spacing. Also try setting line spacing AFTER you finish all text formatting - don’t do it before adding text elements. The rendering engine recalculates spacing based on font sizes and sometimes just ignores values you set earlier.

sounds like a google docs api bug tbh. i’ve hit similar weirdness where the getter returns correct value but rendering ignores it. try setting paragraph spacing instead of line spacing - sometimes that works better for tight layouts in apps script.

try setSpacingAfter(0) on the paragraph - that usually gets around the line spacing limits. worked for me when I was building invoice templates with tight formatting requirements.

Yes, this seems to be a quirk in Google Docs when dealing with mixed font sizes within the same paragraph. Since you have text sized at 28pt and 12pt, the rendering engine prioritizes the larger font size, which leads to the 0.5 line spacing being ignored. I encountered a similar issue during my work with automated document generation. A solution that worked for me was to apply setSpacingBefore and setSpacingAfter on different paragraphs instead of controlling line spacing within a single paragraph. Alternatively, you could set all text to the same font size initially, apply your desired line spacing, and then adjust individual text sizes afterward.

Yeah, this is a known bug in Google Apps Script API. Google Docs calculates minimum line spacing based on your paragraph’s largest font. So when you mix 28pt and 12pt text, it ignores your 0.5 value and uses its own minimum instead. I hit this same problem last year building automated certificates. My fix was ditching setLineSpacing() and using setAttributes() on the paragraph instead. Create a custom style object that bundles line spacing with your other formatting. The attributes method seems to dodge the restrictions that hit the direct spacing methods.

I’ve dealt with Google Apps Script quirks for years - this one’s super annoying. It happens because Apps Script handles line spacing weirdly when you mix font sizes in the same paragraph.

Don’t fight Google’s rendering engine. Automate this differently instead.

I built a workflow that pulls data from Sheets, formats everything exactly how I want with custom spacing controls, then pushes the final content back to Docs. Completely bypasses all the Apps Script formatting issues.

The automation creates documents, applies consistent formatting rules, and gives you full spacing control without the API quirks. You can modify formatting logic easily without diving into Apps Script code constantly.

Latenode handles this workflow really well - great for Google Workspace integrations and you won’t hit these random formatting restrictions: https://latenode.com