spaceBefore property

ParagraphFormat.spaceBefore property

Gets or sets the amount of spacing (in points) before the paragraph.

get spaceBefore(): number

Exceptions

exceptioncondition
RuntimeError (Proxy error(ArgumentOutOfRangeException))Throws when argument was out of the range of valid values.

Remarks

Has no effect when ParagraphFormat.spaceBeforeAuto is true.

Valid values range from 0 to 1584 inclusive.

Examples

Shows how to set automatic paragraph spacing.

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder.paragraphFormat.spaceBefore = 24;
builder.paragraphFormat.spaceAfter = 24;

// Set these flags to "true" to apply automatic spacing,
// effectively ignoring the spacing in the properties we set above.
// Leave them as "false" will apply our custom paragraph spacing.
builder.paragraphFormat.spaceAfterAuto = autoSpacing;
builder.paragraphFormat.spaceBeforeAuto = autoSpacing;

// Insert two paragraphs that will have spacing above and below them and save the document.
builder.writeln("Paragraph 1.");
builder.writeln("Paragraph 2.");

doc.save(base.artifactsDir + "ParagraphFormat.ParagraphSpacingAuto.docx");

Shows how to apply no spacing between paragraphs with the same style.

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

// Apply a large amount of spacing before and after paragraphs that this builder will create.
builder.paragraphFormat.spaceBefore = 24;
builder.paragraphFormat.spaceAfter = 24;

// Set the "NoSpaceBetweenParagraphsOfSameStyle" flag to "true" to apply
// no spacing between paragraphs with the same style, which will group similar paragraphs.
// Leave the "NoSpaceBetweenParagraphsOfSameStyle" flag as "false"
// to evenly apply spacing to every paragraph.
builder.paragraphFormat.noSpaceBetweenParagraphsOfSameStyle = noSpaceBetweenParagraphsOfSameStyle;

builder.paragraphFormat.style = doc.styles.at("Normal");
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.paragraphFormat.style = doc.styles.at("Quote");
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.paragraphFormat.style = doc.styles.at("Normal");
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);
builder.writeln(`Paragraph in the \"${builder.paragraphFormat.style.name}\" style.`);

doc.save(base.artifactsDir + "ParagraphFormat.ParagraphSpacingSameStyle.docx");

See Also