PDFLibPDF generation for Ring

Drawing, tables, images and output

Shapes, line style, images, tables, lists, charts, page numbers, headers, footers, watermarks, graphics state and saving.

Paragraphs#

Both functions return the Y position after the last line, which can be used to continue drawing below the paragraph.

Ring
newY = pdf.drawParagraph(text, x, y, maxWidth, lineHeight)
newY = pdf.drawParagraphAligned(text, x, y, maxWidth, lineHeight, align)

lineHeight defaults to fontSize × 1.2 when NULL is passed.

Shapes#

Rectangles#

Ring
pdf.drawRect(x, y, width, height)                # Stroke only
pdf.drawFilledRect(x, y, width, height)           # Fill and stroke
pdf.drawFilledRectNoStroke(x, y, width, height)   # Fill only

Circles and Ellipses#

Ring
pdf.drawCircle(cx, cy, radius)
pdf.drawFilledCircle(cx, cy, radius)

pdf.drawEllipse(cx, cy, rx, ry)
pdf.drawFilledEllipse(cx, cy, rx, ry)

Lines#

Ring
pdf.drawLine(x1, y1, x2, y2)
pdf.drawHorizontalRule(x, y, width)    # Horizontal line

Polygons#

Ring
# Points is a list of [x, y] pairs; polygon is always filled and stroked
pdf.drawPolygon([[x1, y1], [x2, y2], [x3, y3], ...])

Line Style#

Ring
pdf.setLineWidth(width)
pdf.setLineCap(cap)     # 0 = butt (PDF_CAP_BUTT), 1 = round, 2 = square
pdf.setLineJoin(join)   # 0 = miter (PDF_JOIN_MITER), 1 = round, 2 = bevel
pdf.setDash([5, 3], 0)  # Dash array and phase
pdf.resetDash()         # Restore solid line

Images#

drawImage detects the file format automatically by its header bytes and embeds accordingly. No external image library is required.

Ring
pdf.drawImage(filename, x, y, width, height)
FormatEncodingNotes
JPEG (.jpg, .jpeg)DCTDecodeAll standard JPEG files; dimensions parsed from SOF marker
PNG (.png)FlateDecodeGrayscale, RGB, grayscale+alpha, RGBA; predictor 15
BMP (.bmp)Raw RGB24-bit BMP only; rows converted from BGR bottom-up to RGB top-down
Ring
# JPEG
pdf.drawImage("photo.jpg", 72, 500, 200, 150)

# PNG (all color types supported)
pdf.drawImage("logo.png", 72, 400, 100, 100)

# BMP (24-bit)
pdf.drawImage("scan.bmp", 72, 300, 150, 100)

Width and height are the display dimensions in points (72 pt = 1 inch). The image is scaled to fit the specified rectangle regardless of its pixel dimensions.

Tables#

Explicit Column Widths#

Ring
# data is a 2D list; first row is the header
newY = pdf.drawTable(data, x, y, colWidths, options)

Auto Column Widths#

Ring
# Divides totalWidth evenly across all columns
newY = pdf.drawSimpleTable(data, x, y, totalWidth, options)

Both return the Y position after the last row.

Table options:

KeyDefaultDescription
:rowHeight20Row height in points
:headerBg[66, 133, 244]Header background color
:headerFg[255, 255, 255]Header text color
:evenRowBg[240, 240, 240]Even row background color
:borderColor[0, 0, 0]Cell border color
:fontSize10Text size in points
:showHeadertrueShow or hide the header row
:padding5Cell padding in points
:arabicFont""Font alias for Arabic cell content (enables mixed-script cells)

Lists#

Ring
newY = pdf.drawBulletList(items, x, y, lineHeight)
newY = pdf.drawNumberedList(items, x, y, lineHeight)

items is a list of strings. lineHeight defaults to fontSize × 1.4 when NULL. Both return the Y position after the last item.

Charts#

Bar Chart#

Ring
data = [:labels = ["Q1", "Q2", "Q3"], :values = [120, 200, 170]]
pdf.drawBarChart(data, x, y, width, height, options)
OptionDescription
:titleChart title drawn above the chart
:colorsList of RGB arrays for bars
:showValuestrue to draw each bar's value above it

Pie Chart#

Ring
data = [:labels = ["Alpha", "Beta", "Gamma"], :values = [40, 35, 25]]
pdf.drawPieChart(data, cx, cy, radius, options)
OptionDescription
:colorsList of RGB arrays for slices
:showLegendtrue to draw a legend to the right of the chart

Page Numbers#

Ring
pdf.enablePageNumbers()
pdf.setPageNumberFormat("Page {n} of {total}")   # {n} and {total} are placeholders
pdf.setPageNumberPosition(x, y)                  # Default: horizontally centered, y = 30

Page numbers are added to all pages automatically at save time.

Headers and Footers#

Ring
pdf.setHeader("My Document", PDF_ALIGN_CENTER)
pdf.setFooter("Confidential", PDF_ALIGN_RIGHT)

Headers and footers are drawn on every page at save time using 10 pt Helvetica in gray. The align parameter is a PDF_ALIGN_* constant and defaults to PDF_ALIGN_LEFT.

Watermarks#

Ring
pdf.drawWatermark("DRAFT", [
    :fontSize = 60,
    :color = [200, 200, 200],
    :angle = 45
])

All three options are optional. Defaults are fontSize 60, light gray, angle 45°. The watermark is centered on the current page.

Graphics State#

Ring
pdf.saveState()     # Push current graphics state (color, line width, etc.)
pdf.restoreState()  # Pop and restore previously saved state

Output#

Ring
ok = pdf.save("output.pdf")   # Returns true on success, false on failure
PDFLib - PDF generation for Ring, made with ringdoc.