PDFLibPDF generation for Ring

Examples

An invoice, a certificate, an Arabic document and images.

Invoice#

Ring
load "pdflib.ring"

pdf = new PDFWriter()
pdf.setTitle("Invoice #1001")

pdf.setFont(PDF_HELVETICA_BOLD, 28)
pdf.setTextColor("navy")
pdf.drawText("INVOICE", 72, 760)

pdf.setFont(PDF_HELVETICA, 12)
pdf.setTextColor("gray")
pdf.drawTextRight("#INV-1001", 540, 760)
pdf.drawTextRight("Date: 2025-01-15", 540, 740)

items = [
    ["Description", "Qty", "Price", "Total"],
    ["Web Design", "1", "$2,500", "$2,500"],
    ["Hosting (Annual)", "1", "$300", "$300"],
    ["Domain Name", "2", "$15", "$30"]
]

pdf.drawTable(items, 72, 650, [250, 60, 80, 78], [
    :headerBg = "navy",
    :headerFg = "white"
])

pdf.setFont(PDF_HELVETICA_BOLD, 14)
pdf.setTextColor("black")
pdf.drawTextRight("Total: $2,830.00", 540, 540)

pdf.save("invoice.pdf")

Certificate#

Ring
load "pdflib.ring"

pdf = new PDFWriter()
pdf.setOrientation(PDF_LANDSCAPE)

pdf.setStrokeColor("gold")
pdf.setLineWidth(4)
pdf.drawRect(30, 30, 781, 531)

pdf.setFont(PDF_TIMES_BOLD, 36)
pdf.setTextColor("navy")
pdf.drawTextCentered("Certificate of Achievement", 420, 460)

pdf.setFont(PDF_TIMES_ITALIC, 24)
pdf.setTextColor("black")
pdf.drawTextCentered("Jane Smith", 420, 350)

pdf.setFont(PDF_TIMES, 14)
pdf.drawTextCentered("For outstanding contributions to the team", 420, 300)

pdf.save("certificate.pdf")

Arabic Document#

Ring
load "pdflib.ring"

pdf = new PDFWriter()
pdf.setTitle("Arabic Demo")

# Load a TrueType font for Arabic rendering
pdf.loadArabicFont("font/arial.ttf", "Arabic")

# English heading
pdf.setFont(PDF_HELVETICA_BOLD, 16)
pdf.setTextColor("black")
pdf.drawText("Bilingual Document", 72, 760)

# Arabic heading — x is the right edge
pdf.setFont("Arabic", 20)
pdf.drawArabicText("وثيقة ثنائية اللغة", 523, 760)

# Arabic paragraph with RTL word wrap
pdf.setFont("Arabic", 14)
pdf.drawArabicParagraph(
    "لغة البرمجة رينج هي لغة حديثة وسهلة التعلم تدعم البرمجة الكائنية",
    523, 720, 440, 22
)

pdf.save("arabic_demo.pdf")

Images#

Ring
load "pdflib.ring"

pdf = new PDFWriter()
pdf.setTitle("Image Gallery")

# JPEG
pdf.drawImage("photo.jpg", 72, 560, 200, 150)

# PNG (transparent backgrounds and all color types supported)
pdf.drawImage("logo.png", 300, 560, 120, 120)

# BMP (24-bit)
pdf.drawImage("scan.bmp", 72, 380, 180, 140)

pdf.save("gallery.pdf")
PDFLib - PDF generation for Ring, made with ringdoc.