DOCXLibWord documents for Ring

Images, watermarks and borders

Inline and floating images, cropping, image and text watermarks, page borders and background.

Images#

Inline Images#

MethodParametersDescription
addImage()imagePath, widthCm, heightCmInline image, left-aligned
addImageCentered()imagePath, widthCm, heightCmInline image, centred on page
addImageWithOptions()imagePath, widthCm, heightCm, optionsInline image, left-aligned, with options
addImageCenteredWithOptions()imagePath, widthCm, heightCm, optionsInline image, centred, with options

Supported formats: PNG, JPG/JPEG, GIF, BMP.

Image options (used with addImageWithOptions() and addImageCenteredWithOptions()):

OptionTypeDescription
:altTextStringAccessibility description
:cropLeftNumberTrim left side by this percentage (0–100)
:cropRightNumberTrim right side by this percentage
:cropTopNumberTrim top by this percentage
:cropBottomNumberTrim bottom by this percentage
Ring
# Basic inline image
doc.addImage("logo.png", 5, 3)
doc.addImageCentered("chart.png", 12, 8)

# With options (altText, crop)
doc.addImageCenteredWithOptions("chart.png", 12, 8, [:altText="Benchmark chart"])

# Crop: remove 15% from each side, 10% from top (non-destructive)
doc.addImageCenteredWithOptions("photo.jpg", 12, 8, [
    :cropLeft = 15, :cropRight = 15, :cropTop = 10
])

# Centre punch-out — shows only the inner 60×60% of the image
doc.addImageWithOptions("landscape.png", 10, 6, [
    :cropLeft=20, :cropRight=20, :cropTop=20, :cropBottom=20
])
Note

Note: Cropping is non-destructive. The full image is embedded; only the displayed viewport changes. Uses the OOXML a:srcRect element.

Floating Images#

addFloatingImage() positions an image independently of the text flow.

Ring
doc.addFloatingImage("logo.png", 4, 3, [
    :wrapType = "wrapSquare",
    :wrapSide = "right",
    :posX     = 100,
    :posY     = 200,
    :distCm   = 0.3,
    :altText  = "Company logo",
    :cropTop  = 5,
    :cropBottom = 5
])

Image Watermarks#

MethodParametersDescription
setImageWatermark()imagePath, optionsBackground image watermark on every page
removeImageWatermark()—Remove the image watermark
OptionTypeDescription
:widthCmNumberWatermark width in cm. Default: 15
:heightCmNumberWatermark height in cm. Default: 15
:opacityNumberOpacity 0–100. Default: 50
Ring
doc.setImageWatermark("logo_grey.png", [:widthCm=10, :opacity=25])

Text Watermarks#

MethodParametersDescription
setWatermark()text, optionsDiagonal text watermark on every page
setWatermarkText()textChange watermark text, keep other settings
removeWatermark()—Remove the text watermark
OptionTypeDescription
:colorStringHex colour. Default: C0C0C0
:opacityNumberOpacity 0–100. Default: 50
:rotationNumberRotation in degrees (negative = tilt left). Default: –45
:fontStringFont name. Default: Arial
:sizeNumberFont size in pt. Default: 72
Ring
# Simple DRAFT watermark
doc.setWatermarkText("DRAFT")

# Custom watermark
doc.setWatermark("CONFIDENTIAL", [
    :color    = "FF0000",
    :opacity  = 30,
    :rotation = -45,
    :size     = 96
])

Page Borders and Background#

MethodParametersDescription
setPageBorder()optionsAdd borders around every page
setSimplePageBorder()—Single-line 3pt black border on all four sides
removePageBorder()—Remove the page border
setPageBackground()colorSolid background colour for all pages hex
setPageBorder() optionTypeDescription
:styleString"single", "double", "thick", "dashed", "dotted", "shadow"
:colorStringBorder colour hex. Default: 000000
:sizeNumberWidth in eighths of a point. 24 = 3pt
:spaceNumberGap from page edge in points. Default: 24
:offsetFromString"page" or "text"
:sidesList["top","bottom","left","right"]. Default: all four
Ring
# Simple border
doc.setSimplePageBorder()

# Custom — top and bottom only, thick blue
doc.setPageBorder([
    :style = "single",
    :color = "1E6BB5",
    :size  = 48,
    :sides = ["top", "bottom"]
])

# Light blue background
doc.setPageBackground("EBF3FB")
DOCXLib - Word documents for Ring, made with ringdoc.