PDFLibPDF generation for Ring

Document, pages and text

The constructor, document settings, pages, fonts, Arabic and Unicode text, colors, text and paragraphs.

Constructor#

Ring
pdf = new PDFWriter()

Creates a new PDF document with one blank A4 page. All 14 PDF standard fonts are pre-registered and ready to use — no font files required.

Document Settings#

MethodDescription
setPageSize(size)Page size constant — see Page Sizes table
setOrientation(orient)PDF_PORTRAIT or PDF_LANDSCAPE
setMargins(left, top, right, bottom)Margins in points (72 pt = 1 inch). Default: 72 all sides
setTitle(text)Document title
setAuthor(text)Author name
setSubject(text)Subject
setKeywords(text)Keywords
setCreator(text)Creator application name

Page Sizes#

ConstantPointsPhysical
PDF_A4595.28 × 841.89210 × 297 mm
PDF_A3841.89 × 1190.55297 × 420 mm
PDF_A5419.53 × 595.28148 × 210 mm
PDF_LETTER612 × 7928.5 × 11 in
PDF_LEGAL612 × 10088.5 × 14 in
PDF_TABLOID792 × 122411 × 17 in

Page Management#

MethodReturnsDescription
addPage()selfAdd a new page and switch to it
selectPage(n)selfSwitch to page n (1-based)
getPageCount()numberTotal number of pages
getPageWidth()numberCurrent page width in points
getPageHeight()numberCurrent page height in points
getContentWidth()numberPage width minus left and right margins
getContentHeight()numberPage height minus top and bottom margins

Fonts#

PDFLib supports two categories of fonts: PDF standard fonts for Latin text, and TrueType fonts for Arabic/Unicode text.

PDF Standard Fonts#

The PDF specification (ISO 32000) defines 14 standard fonts that every conforming PDF viewer is required to have built in. PDFLib references these by name only — no font files are shipped or embedded; the viewer supplies the glyphs. This makes standard-font PDFs very small.

Set the active font with setFont(fontName, size) or change only the size with setFontSize(size).

Ring
pdf.setFont(PDF_HELVETICA_BOLD, 18)
pdf.setFontSize(12)
ConstantPDF Font NameStyle
PDF_HELVETICAHelveticaSans-serif
PDF_HELVETICA_BOLDHelvetica-BoldSans-serif bold
PDF_HELVETICA_ITALICHelvetica-ObliqueSans-serif italic
PDF_HELVETICA_BOLDITALICHelvetica-BoldObliqueSans-serif bold italic
PDF_TIMESTimes-RomanSerif
PDF_TIMES_BOLDTimes-BoldSerif bold
PDF_TIMES_ITALICTimes-ItalicSerif italic
PDF_TIMES_BOLDITALICTimes-BoldItalicSerif bold italic
PDF_COURIERCourierMonospace
PDF_COURIER_BOLDCourier-BoldMonospace bold
PDF_COURIER_ITALICCourier-ObliqueMonospace italic
PDF_COURIER_BOLDITALICCourier-BoldObliqueMonospace bold italic
PDF_SYMBOLSymbolGreek and mathematical symbols
PDF_ZAPFDINGBATSZapfDingbatsDecorative dingbats
Note

Note: Standard fonts only cover the Latin-1 (Western) character set. They do not support Arabic, Hebrew, Chinese, or other non-Latin scripts. For Arabic text, a TrueType font must be loaded separately — see the Arabic / Unicode Text section.

TrueType Fonts#

Any .ttf file can be loaded. The font is fully parsed (cmap, hmtx, glyf, head, hhea, loca, OS/2, and post tables) and embedded in the output PDF as a CIDFont/Type0 object with a ToUnicode CMap. No external tool or C library is needed.

Ring
pdf.loadTTFFont("font/arial.ttf", "Arabic")    # general method
pdf.loadArabicFont("font/arial.ttf", "Arabic") # alias — identical behaviour
pdf.setFont("Arabic", 24)

The second argument is a free-form alias used with setFont. The library ships font/arial.ttf in the samples folder as a ready-to-use example; any other TTF can be substituted.

Script support matrix:

ScriptMethod to useNotes
ArabicdrawArabicText / drawArabicParagraphFull support: contextual shaping, RTL layout, word wrap
Latin extensions (é, ü, ñ …)drawTextWorks — direct codepoint-to-glyph mapping, no shaping needed
Greek, CyrillicdrawTextWorks — no shaping required
CJK (Chinese, Japanese, Korean)drawTextWorks — one codepoint maps to one glyph
Hebrew (basic)drawTextGlyphs render but no RTL layout support outside the Arabic path
Devanagari (Hindi), Thai, Khmer, Myanmar—Not supported — these scripts require a shaping engine not present in the library
Note

In short: load any TTF and use drawText for scripts that don't need complex shaping. Use the drawArabicText family specifically for Arabic, which is the only script with a full shaping and bidirectional layout pipeline implemented.

Arabic / Unicode Text#

PDFLib includes a pure Ring Arabic text engine supporting UTF-8 decoding, contextual letter shaping (isolated/initial/medial/final letter forms), bidi reordering, and right-to-left layout. A TrueType font must be loaded first — see TrueType Fonts above.

Drawing Arabic Text#

MethodDescription
drawArabicText(text, x, y)Draw Arabic text; x is the right edge of the text (RTL)
drawArabicTextLeft(text, x, y)Draw Arabic text with x as the left edge
drawArabicTextCentered(text, x, y)Draw Arabic text centered at x
drawArabicTextInCell(text, x, y)Draw Arabic text in a LTR cell context (left-edge x)
drawArabicParagraph(text, x, y, maxWidth, lineHeight)RTL word-wrapped paragraph; x is right edge; returns final Y
getArabicTextWidth(text)Returns rendered width in points for the current font and size
Ring
pdf.loadArabicFont("font/arial.ttf", "Arabic")
pdf.setFont("Arabic", 28)
pdf.setTextColor("black")

# x = 523 is the right edge of the text
pdf.drawArabicText("مرحبا بالعالم", 523, 700)

# RTL paragraph with word wrap, max width 441 pt
pdf.drawArabicParagraph("لغة البرمجة رينج هي لغة حديثة وسهلة التعلم", 523, 600, 441, 28)

Mixed Arabic/Latin Documents#

When an arabicFont option is passed to drawTable, cells are automatically rendered with the correct font and direction based on their content. Arabic segments within a mixed cell are drawn right-to-left; Latin segments are drawn left-to-right.

Ring
pdf.drawTable(data, 72, 700, [200, 268], [
    :headerBg = "navy",
    :headerFg = "white",
    :arabicFont = "Arabic"
])

Colors#

Ring
pdf.setTextColor(color)
pdf.setFillColor(color)
pdf.setStrokeColor(color)

Colors can be specified in three formats:

Named colors: black, white, red, green, blue, yellow, orange, purple, pink, gray, grey, navy, teal, maroon, silver, lime, aqua, cyan, fuchsia, olive, brown, coral, crimson, gold, indigo, salmon, steelblue, tomato, darkblue, darkgreen, darkred, lightgray, lightgrey, darkgray, darkgrey

Text Drawing#

Ring
pdf.drawText(text, x, y)                          # Left-aligned at (x, y)
pdf.drawTextCentered(text, x, y)                  # Horizontally centered at x
pdf.drawTextRight(text, x, y)                     # Right edge at x
pdf.drawTextAligned(text, x, y, width, align)     # Within a box of given width

Alignment constants:

ConstantValue
PDF_ALIGN_LEFT0
PDF_ALIGN_CENTER1
PDF_ALIGN_RIGHT2
PDFLib - PDF generation for Ring, made with ringdoc.