Images, watermarks and borders
Inline and floating images, cropping, image and text watermarks, page borders and background.
Images#
Inline Images#
| Method | Parameters | Description |
|---|
addImage() | imagePath, widthCm, heightCm | Inline image, left-aligned |
addImageCentered() | imagePath, widthCm, heightCm | Inline image, centred on page |
addImageWithOptions() | imagePath, widthCm, heightCm, options | Inline image, left-aligned, with options |
addImageCenteredWithOptions() | imagePath, widthCm, heightCm, options | Inline image, centred, with options |
Supported formats: PNG, JPG/JPEG, GIF, BMP.
Image options (used with addImageWithOptions() and addImageCenteredWithOptions()):
| Option | Type | Description |
|---|
:altText | String | Accessibility description |
:cropLeft | Number | Trim left side by this percentage (0–100) |
:cropRight | Number | Trim right side by this percentage |
:cropTop | Number | Trim top by this percentage |
:cropBottom | Number | Trim 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
])
NoteNote: 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#
| Method | Parameters | Description |
|---|
setImageWatermark() | imagePath, options | Background image watermark on every page |
removeImageWatermark() | — | Remove the image watermark |
| Option | Type | Description |
|---|
:widthCm | Number | Watermark width in cm. Default: 15 |
:heightCm | Number | Watermark height in cm. Default: 15 |
:opacity | Number | Opacity 0–100. Default: 50 |
Ring
doc.setImageWatermark("logo_grey.png", [:widthCm=10, :opacity=25])
Text Watermarks#
| Method | Parameters | Description |
|---|
setWatermark() | text, options | Diagonal text watermark on every page |
setWatermarkText() | text | Change watermark text, keep other settings |
removeWatermark() | — | Remove the text watermark |
| Option | Type | Description |
|---|
:color | String | Hex colour. Default: C0C0C0 |
:opacity | Number | Opacity 0–100. Default: 50 |
:rotation | Number | Rotation in degrees (negative = tilt left). Default: –45 |
:font | String | Font name. Default: Arial |
:size | Number | Font 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#
| Method | Parameters | Description |
|---|
setPageBorder() | options | Add borders around every page |
setSimplePageBorder() | — | Single-line 3pt black border on all four sides |
removePageBorder() | — | Remove the page border |
setPageBackground() | color | Solid background colour for all pages hex |
setPageBorder() option | Type | Description |
|---|
:style | String | "single", "double", "thick", "dashed", "dotted", "shadow" |
:color | String | Border colour hex. Default: 000000 |
:size | Number | Width in eighths of a point. 24 = 3pt |
:space | Number | Gap from page edge in points. Default: 24 |
:offsetFrom | String | "page" or "text" |
:sides | List | ["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")