PDFLibPDF generation for Ring

Samples

The sample programs of the package.

See the folder samples/UsingPDFLib. Each sample writes a .pdf file with the name of the sample to the current folder. Each sample name links to its source code in this documentation (below the table) and to the file on GitHub.

SampleDescriptionCode
hello.ringThe first PDF: a title and a line of textGitHub
quick.ringA document from a list of pages using quickPDF()GitHub
invoice.ringAn invoice with a tableGitHub
certificate.ringA certificateGitHub
gallery.ringA gallery of images and shapesGitHub
demo_general.ringA demo of the features of the libraryGitHub
demo_arabic.ringArabic text: shaping, right-to-left layout and mixed Arabic and Latin textGitHub
demo_images.ringEmbedding PNG, JPEG and BMP imagesGitHub

Source code#

hello.ring#

samples/UsingPDFLib/hello.ring
samples/UsingPDFLib/hello.ring
load "pdflib.ring"

func main

	cFileName = substr(filename(),".ring",".pdf")
	? "Generate File: " + cFileName

	new PDFWriter() {
		setTitle("My First PDF")
		setFont(PDF_HELVETICA_BOLD, 24)
		drawText("Hello, World!", 72, 700)
		save(cFileName)
	}

	? "Done..."

quick.ring#

samples/UsingPDFLib/quick.ring
samples/UsingPDFLib/quick.ring
load "pdflib.ring"

func main

	cFileName = substr(filename(),".ring",".pdf")
	? "Generate File: " + cFileName

	quickPDF(cFileName, "My Document", [
		[:title = "Page 1", :body = "Content for page 1..."],
		[:title = "Page 2", :body = "Content for page 2..."]
	])

	? "Done..."

invoice.ring#

samples/UsingPDFLib/invoice.ring
samples/UsingPDFLib/invoice.ring
load "pdflib.ring"

func main

	cFileName = substr(filename(),".ring",".pdf")
	? "Generate File: " + cFileName

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

	new PDFWriter() {
		setTitle("Invoice #1001")
		setFont(PDF_HELVETICA_BOLD, 28)
		setTextColor("navy")
		drawText("INVOICE", 72, 760)
		setFont(PDF_HELVETICA, 12)
		setTextColor("gray")
		drawTextRight("#INV-1001", 540, 760)
		drawTextRight("Date: 2025-01-15", 540, 740)
		drawTable(items, 72, 650, [250, 60, 80, 78], [
    			:headerBg = "navy",
    			:headerFg = "white"
		])
		setFont(PDF_HELVETICA_BOLD, 14)
		setTextColor("black")
		drawTextRight("Total: $2,830.00", 540, 540)
		save(cFileName)
	}

	? "Done..."

certificate.ring#

samples/UsingPDFLib/certificate.ring
samples/UsingPDFLib/certificate.ring
load "pdflib.ring"

func main

	cFileName = substr(filename(),".ring",".pdf")
	? "Generate File: " + cFileName

	new PDFWriter() {
		setOrientation(PDF_LANDSCAPE)
		setStrokeColor("gold")
		setLineWidth(4)
		drawRect(30, 30, 781, 531)
		setFont(PDF_TIMES_BOLD, 36)
		setTextColor("navy")
		drawTextCentered("Certificate of Achievement", 420, 460)
		setFont(PDF_TIMES_ITALIC, 24)
		setTextColor("black")
		drawTextCentered("Jane Smith", 420, 350)
		setFont(PDF_TIMES, 14)
		drawTextCentered("For outstanding contributions to the team", 420, 300)
		save(cFileName)
	}

? "Done..."

gallery.ring#

samples/UsingPDFLib/gallery.ring
samples/UsingPDFLib/gallery.ring
load "pdflib.ring"

func main

	cFileName = substr(filename(),".ring",".pdf")
	? "Generate File: " + cFileName

	new PDFWriter() {
		setTitle("Image Gallery")
		drawImage("images/test2.jpg", 72, 560, 200, 150)
		drawImage("images/test1.png", 300, 560, 120, 120)
		drawImage("images/test3.bmp", 72, 380, 180, 140)
		save(cFileName)
	}

	? "Done..."

demo_general.ring#

samples/UsingPDFLib/demo_general.ring
samples/UsingPDFLib/demo_general.ring
/*
    PDFLib Demo - PDF Generation in Ring
    ====================================
    Demonstrates all features of PDFLib
*/

load "pdflib.ring"

func main

    ? "=============================================="
    ? "   PDFLib Demo - PDF Generation in Ring"
    ? "=============================================="
    ? ""

    # ------------------------------------------------------------------
    # Demo 1: Hello World
    # ------------------------------------------------------------------
    ? "Demo 1: Hello World..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Hello World")
    pdfDoc.setAuthor("RingPDFLib Demo")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 36)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Hello, PDF World!", 72, 700)

    pdfDoc.setFont(PDF_HELVETICA, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("This PDF was generated using RingPDFLib.", 72, 660)
    pdfDoc.drawText("A pure Ring implementation with no dependencies.", 72, 640)

    if pdfDoc.save("demo1_hello.pdf")
        ? "  Created: demo1_hello.pdf"
    else
        ? "  FAILED: demo1_hello.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 2: Text and Fonts
    # ------------------------------------------------------------------
    ? "Demo 2: Text and fonts..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Font Showcase")

    curY = 750

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Font Showcase", 72, curY)
    curY -= 40

    # Helvetica family
    pdfDoc.setFont(PDF_HELVETICA, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Helvetica Normal - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.drawText("Helvetica Bold - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_HELVETICA_ITALIC, 14)
    pdfDoc.drawText("Helvetica Italic - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_HELVETICA_BOLDITALIC, 14)
    pdfDoc.drawText("Helvetica Bold Italic - The quick brown fox jumps.", 72, curY)
    curY -= 35

    # Times family
    pdfDoc.setFont(PDF_TIMES, 14)
    pdfDoc.drawText("Times Roman - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_TIMES_BOLD, 14)
    pdfDoc.drawText("Times Bold - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_TIMES_ITALIC, 14)
    pdfDoc.drawText("Times Italic - The quick brown fox jumps.", 72, curY)
    curY -= 35

    # Courier family
    pdfDoc.setFont(PDF_COURIER, 14)
    pdfDoc.drawText("Courier - The quick brown fox jumps.", 72, curY)
    curY -= 22

    pdfDoc.setFont(PDF_COURIER_BOLD, 14)
    pdfDoc.drawText("Courier Bold - The quick brown fox jumps.", 72, curY)
    curY -= 35

    # Font sizes
    pdfDoc.setFont(PDF_HELVETICA, 8)
    pdfDoc.drawText("8pt - Small text", 72, curY)
    curY -= 15

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawText("12pt - Normal text", 72, curY)
    curY -= 20

    pdfDoc.setFont(PDF_HELVETICA, 18)
    pdfDoc.drawText("18pt - Large text", 72, curY)
    curY -= 28

    pdfDoc.setFont(PDF_HELVETICA, 24)
    pdfDoc.drawText("24pt - Extra large text", 72, curY)
    curY -= 40

    # Colors
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("red")
    pdfDoc.drawText("Red Text", 72, curY)

    pdfDoc.setTextColor("green")
    pdfDoc.drawText("Green Text", 220, curY)

    pdfDoc.setTextColor("blue")
    pdfDoc.drawText("Blue Text", 380, curY)
    curY -= 25

    pdfDoc.setTextColor("orange")
    pdfDoc.drawText("Orange", 72, curY)

    pdfDoc.setTextColor("purple")
    pdfDoc.drawText("Purple", 200, curY)

    pdfDoc.setTextColor("#FF6347")
    pdfDoc.drawText("Hex Color", 330, curY)

    if pdfDoc.save("demo2_fonts.pdf")
        ? "  Created: demo2_fonts.pdf"
    else
        ? "  FAILED: demo2_fonts.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 3: Paragraphs and Text Alignment
    # ------------------------------------------------------------------
    ? "Demo 3: Paragraphs and alignment..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Paragraphs and Alignment")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Paragraphs & Alignment", 72, 750)

    # Wrapped paragraph
    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Left-Aligned Paragraph:", 72, 710)

    loremText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."

    curY = pdfDoc.drawParagraph(loremText, 72, 690, 468, 16)
    curY -= 20

    # Center-aligned
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 12)
    pdfDoc.drawText("Center-Aligned Paragraph:", 72, curY)
    curY -= 20

    curY = pdfDoc.drawParagraphAligned("This text is centered. It demonstrates paragraph alignment in RingPDFLib. Each line is centered within the specified width.", 72, curY, 468, 16, PDF_ALIGN_CENTER)
    curY -= 20

    # Right-aligned
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 12)
    pdfDoc.drawText("Right-Aligned Paragraph:", 72, curY)
    curY -= 20

    curY = pdfDoc.drawParagraphAligned("This text is right-aligned. Each line is pushed to the right edge of the specified width.", 72, curY, 468, 16, PDF_ALIGN_RIGHT)

    if pdfDoc.save("demo3_paragraphs.pdf")
        ? "  Created: demo3_paragraphs.pdf"
    else
        ? "  FAILED: demo3_paragraphs.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 4: Shapes and Drawing
    # ------------------------------------------------------------------
    ? "Demo 4: Shapes and drawing..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Shapes and Drawing")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Shapes & Drawing", 72, 750)

    # Rectangles
    pdfDoc.setFont(PDF_HELVETICA, 11)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Rectangles:", 72, 710)

    pdfDoc.setStrokeColor("black")
    pdfDoc.setLineWidth(1)
    pdfDoc.drawRect(72, 660, 100, 40)

    pdfDoc.setFillColor("steelblue")
    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawFilledRect(190, 660, 100, 40)

    pdfDoc.setFillColor("coral")
    pdfDoc.drawFilledRectNoStroke(310, 660, 100, 40)

    # Circles
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Circles:", 72, 635)

    pdfDoc.setStrokeColor("black")
    pdfDoc.setLineWidth(1)
    pdfDoc.drawCircle(120, 585, 30)

    pdfDoc.setFillColor("green")
    pdfDoc.setStrokeColor("darkgreen")
    pdfDoc.drawFilledCircle(230, 585, 30)

    pdfDoc.setFillColor("gold")
    pdfDoc.setStrokeColor("orange")
    pdfDoc.drawFilledCircle(340, 585, 30)

    # Ellipses
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Ellipses:", 72, 535)

    pdfDoc.setStrokeColor("purple")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawEllipse(130, 490, 60, 30)

    pdfDoc.setFillColor("pink")
    pdfDoc.setStrokeColor("crimson")
    pdfDoc.drawFilledEllipse(290, 490, 50, 25)

    # Lines
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Lines:", 72, 440)

    pdfDoc.setStrokeColor("red")
    pdfDoc.setLineWidth(1)
    pdfDoc.drawLine(72, 425, 250, 425)

    pdfDoc.setStrokeColor("blue")
    pdfDoc.setLineWidth(3)
    pdfDoc.drawLine(72, 410, 250, 410)

    pdfDoc.setStrokeColor("green")
    pdfDoc.setLineWidth(1)
    pdfDoc.setDash([5, 3], 0)
    pdfDoc.drawLine(72, 395, 250, 395)

    pdfDoc.setStrokeColor("orange")
    pdfDoc.setDash([10, 5, 3, 5], 0)
    pdfDoc.drawLine(72, 380, 250, 380)

    pdfDoc.resetDash()

    # Horizontal rule
    pdfDoc.setStrokeColor("gray")
    pdfDoc.setLineWidth(0.5)
    pdfDoc.drawHorizontalRule(72, 350, 468)

    # Polygon
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Polygon:", 72, 330)
    pdfDoc.setFillColor("teal")
    pdfDoc.setStrokeColor("darkblue")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawPolygon([[100, 260], [150, 310], [130, 260], [170, 290], [80, 290]])

    if pdfDoc.save("demo4_shapes.pdf")
        ? "  Created: demo4_shapes.pdf"
    else
        ? "  FAILED: demo4_shapes.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 5: Tables
    # ------------------------------------------------------------------
    ? "Demo 5: Tables..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Tables")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Table Examples", 72, 750)

    # Simple table
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Employee Table:", 72, 710)

    tableData = [
        ["Name", "Department", "Salary", "Location"],
        ["John Smith", "Engineering", "$95,000", "New York"],
        ["Alice Brown", "Marketing", "$82,000", "Chicago"],
        ["Bob Wilson", "Sales", "$78,000", "Austin"],
        ["Carol Davis", "Engineering", "$91,000", "Seattle"],
        ["Dave Miller", "HR", "$75,000", "Boston"]
    ]

    colWidths = [130, 120, 100, 118]

    curY = pdfDoc.drawTable(tableData, 72, 695, colWidths, [
        :headerBg = "steelblue",
        :headerFg = "white",
        :evenRowBg = [230, 240, 250],
        :rowHeight = 22,
        :fontSize = 10
    ])

    curY -= 30

    # Another table with different styling
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Product Inventory:", 72, curY)
    curY -= 15

    productData = [
        ["Product", "SKU", "Stock", "Price"],
        ["Widget A", "WDG-001", "150", "$12.99"],
        ["Gadget B", "GDG-002", "85", "$24.50"],
        ["Tool C", "TL-003", "200", "$8.75"],
        ["Part D", "PT-004", "42", "$45.00"]
    ]

    curY = pdfDoc.drawTable(productData, 72, curY, [130, 110, 100, 128], [
        :headerBg = "darkgreen",
        :headerFg = "white",
        :evenRowBg = [220, 240, 220],
        :rowHeight = 20,
        :fontSize = 10
    ])

    curY -= 30

    # Auto-width table
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.drawText("Auto-Width Table:", 72, curY)
    curY -= 15

    simpleData = [
        ["Day", "Temp", "Weather"],
        ["Monday", "72F", "Sunny"],
        ["Tuesday", "68F", "Cloudy"],
        ["Wednesday", "75F", "Sunny"],
        ["Thursday", "61F", "Rain"]
    ]

    curY = pdfDoc.drawSimpleTable(simpleData, 72, curY, 400, [
        :headerBg = "crimson",
        :fontSize = 10
    ])

    if pdfDoc.save("demo5_tables.pdf")
        ? "  Created: demo5_tables.pdf"
    else
        ? "  FAILED: demo5_tables.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 6: Lists
    # ------------------------------------------------------------------
    ? "Demo 6: Lists..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Lists")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Bullet & Numbered Lists", 72, 750)

    # Bullet list
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Features of RingPDFLib:", 72, 710)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    curY = pdfDoc.drawBulletList([
        "Pure Ring implementation",
        "No external dependencies needed",
        "Multiple page support",
        "14 built-in fonts",
        "Text formatting and alignment",
        "Shapes: rectangles, circles, ellipses",
        "Tables with headers and styling",
        "Charts: bar and pie",
        "Page numbers and headers/footers"
    ], 90, 685, 20)

    curY -= 25

    # Numbered list
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.drawText("Steps to Create a PDF:", 72, curY)
    curY -= 20

    pdfDoc.setFont(PDF_HELVETICA, 12)
    curY = pdfDoc.drawNumberedList([
        "Load the ringpdflib.ring library",
        "Create a new PDFWriter object",
        "Set document properties (title, author)",
        "Add content: text, shapes, tables",
        "Save the document to a file",
        "Open the PDF in any viewer"
    ], 90, curY, 20)

    if pdfDoc.save("demo6_lists.pdf")
        ? "  Created: demo6_lists.pdf"
    else
        ? "  FAILED: demo6_lists.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 7: Multiple Pages
    # ------------------------------------------------------------------
    ? "Demo 7: Multiple pages..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Multi-Page Document")
    pdfDoc.setAuthor("RingPDFLib")

    # Page 1 - Title page
    pdfDoc.setFillColor([41, 98, 255])
    pdfDoc.drawFilledRectNoStroke(0, 0, 595.28, 841.89)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 48)
    pdfDoc.setTextColor("white")
    pdfDoc.drawTextCentered("Annual Report", 297.64, 500)

    pdfDoc.setFont(PDF_HELVETICA, 24)
    pdfDoc.drawTextCentered("2026 Edition", 297.64, 450)

    pdfDoc.setFont(PDF_HELVETICA, 16)
    pdfDoc.drawTextCentered("Ring Programming Language", 297.64, 350)

    # Page 2 - Content
    pdfDoc.addPage()
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 28)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Executive Summary", 72, 750)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 740, 400, 740)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")
    pdfDoc.drawParagraph("This document demonstrates the multi-page capability of RingPDFLib. Each page can have its own content, including text, shapes, tables, and charts. The library handles page management automatically.", 72, 710, 468, 16)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 18)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Key Highlights", 72, 620)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")
    pdfDoc.drawBulletList([
        "Revenue grew 24% year-over-year",
        "Customer base expanded to 50,000+",
        "Launched 3 new product lines",
        "Opened offices in 5 new cities"
    ], 90, 595, 20)

    # Page 3 - Chart page
    pdfDoc.addPage()
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 28)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Financial Overview", 72, 750)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 740, 400, 740)

    chartData = [
        :labels = ["Q1", "Q2", "Q3", "Q4"],
        :values = [320, 450, 520, 680]
    ]

    pdfDoc.drawBarChart(chartData, 72, 450, 400, 250, [
        :title = "Quarterly Revenue ($K)",
        :showValues = true
    ])

    if pdfDoc.save("demo7_multipage.pdf")
        ? "  Created: demo7_multipage.pdf"
    else
        ? "  FAILED: demo7_multipage.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 8: Page Numbers and Headers/Footers
    # ------------------------------------------------------------------
    ? "Demo 8: Page numbers and headers/footers..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Headers and Footers")

    pdfDoc.enablePageNumbers()
    pdfDoc.setPageNumberFormat("Page {n} of {total}")
    pdfDoc.setHeader("RingPDFLib Documentation", PDF_ALIGN_LEFT)
    pdfDoc.setFooter("Confidential", PDF_ALIGN_CENTER)

    # Page 1
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Chapter 1: Introduction", 72, 720)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawParagraph("This is the first page of a multi-page document with headers, footers, and page numbers. The header appears at the top of each page, and the footer and page numbers appear at the bottom.", 72, 690, 468, 16)

    # Page 2
    pdfDoc.addPage()
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Chapter 2: Features", 72, 720)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawParagraph("The second page continues with more content. Notice how headers, footers, and page numbers automatically appear on each page.", 72, 690, 468, 16)

    # Page 3
    pdfDoc.addPage()
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Chapter 3: Conclusion", 72, 720)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawParagraph("The final page demonstrates consistent formatting across all pages in the document.", 72, 690, 468, 16)

    if pdfDoc.save("demo8_headers.pdf")
        ? "  Created: demo8_headers.pdf"
    else
        ? "  FAILED: demo8_headers.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 9: Bar Chart
    # ------------------------------------------------------------------
    ? "Demo 9: Bar chart..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Bar Chart")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Sales Report", 72, 750)

    salesData = [
        :labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
        :values = [85, 120, 95, 150, 130, 170]
    ]

    pdfDoc.drawBarChart(salesData, 72, 400, 450, 280, [
        :title = "Monthly Sales (Units)",
        :showValues = true,
        :colors = [[66,133,244], [52,168,83], [251,188,4], [234,67,53], [171,71,188], [255,109,0]]
    ])

    if pdfDoc.save("demo9_bar_chart.pdf")
        ? "  Created: demo9_bar_chart.pdf"
    else
        ? "  FAILED: demo9_bar_chart.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 10: Pie Chart
    # ------------------------------------------------------------------
    ? "Demo 10: Pie chart..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Pie Chart")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Market Share Analysis", 72, 750)

    marketData = [
        :labels = ["Product A", "Product B", "Product C", "Product D", "Other"],
        :values = [35, 25, 20, 12, 8]
    ]

    pdfDoc.drawPieChart(marketData, 250, 500, 120, [
        :showLegend = true
    ])

    if pdfDoc.save("demo10_pie_chart.pdf")
        ? "  Created: demo10_pie_chart.pdf"
    else
        ? "  FAILED: demo10_pie_chart.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 11: Watermark
    # ------------------------------------------------------------------
    ? "Demo 11: Watermark..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Watermark Demo")

    # Content first
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Important Document", 72, 750)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")
    pdfDoc.drawParagraph("This document contains a watermark. Watermarks are useful for marking documents as drafts, confidential, or for branding purposes. The watermark appears behind the text content.", 72, 710, 468, 16)

    # Add watermark
    pdfDoc.drawWatermark("CONFIDENTIAL", [
        :fontSize = 60,
        :color = [220, 220, 220],
        :angle = 45
    ])

    if pdfDoc.save("demo11_watermark.pdf")
        ? "  Created: demo11_watermark.pdf"
    else
        ? "  FAILED: demo11_watermark.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 12: Landscape Page
    # ------------------------------------------------------------------
    ? "Demo 12: Landscape orientation..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Landscape Page")
    pdfDoc.setOrientation(PDF_LANDSCAPE)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 28)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Landscape Orientation", 72, 520)

    pdfDoc.setFont(PDF_HELVETICA, 14)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("This page uses landscape orientation for wider content.", 72, 480)

    # Wide table
    wideData = [
        ["Region", "Q1 Sales", "Q2 Sales", "Q3 Sales", "Q4 Sales", "Total", "Growth"],
        ["North", "$120K", "$135K", "$142K", "$160K", "$557K", "+15%"],
        ["South", "$98K", "$105K", "$112K", "$125K", "$440K", "+12%"],
        ["East", "$145K", "$150K", "$155K", "$170K", "$620K", "+8%"],
        ["West", "$110K", "$118K", "$130K", "$145K", "$503K", "+18%"]
    ]

    pdfDoc.drawTable(wideData, 72, 440, [100, 90, 90, 90, 90, 90, 90], [
        :headerBg = "steelblue",
        :headerFg = "white",
        :evenRowBg = [235, 240, 250],
        :rowHeight = 24,
        :fontSize = 11
    ])

    if pdfDoc.save("demo12_landscape.pdf")
        ? "  Created: demo12_landscape.pdf"
    else
        ? "  FAILED: demo12_landscape.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 13: Business Report
    # ------------------------------------------------------------------
    ? "Demo 13: Business report..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Business Report")
    pdfDoc.setAuthor("Ring Corporation")
    pdfDoc.enablePageNumbers()

    # --- Title Page ---
    pdfDoc.setFillColor([33, 37, 41])
    pdfDoc.drawFilledRectNoStroke(0, 0, 595.28, 841.89)

    pdfDoc.setFillColor([66, 133, 244])
    pdfDoc.drawFilledRectNoStroke(0, 350, 595.28, 200)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 42)
    pdfDoc.setTextColor("white")
    pdfDoc.drawTextCentered("Business Report", 297.64, 465)

    pdfDoc.setFont(PDF_HELVETICA, 20)
    pdfDoc.drawTextCentered("Q4 2026 Performance Review", 297.64, 420)

    pdfDoc.setFont(PDF_HELVETICA, 14)
    pdfDoc.drawTextCentered("Prepared by the Analytics Team", 297.64, 380)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor([150, 150, 150])
    pdfDoc.drawTextCentered("Ring Corporation - January 2026", 297.64, 200)

    # --- Page 2: KPI Overview ---
    pdfDoc.addPage()

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Key Performance Indicators", 72, 760)

    pdfDoc.setStrokeColor([66, 133, 244])
    pdfDoc.setLineWidth(3)
    pdfDoc.drawLine(72, 750, 300, 750)

    # KPI Cards
    kpiX = 72
    kpiY = 680
    kpiW = 145
    kpiH = 70

    # Card 1
    pdfDoc.setFillColor([230, 240, 255])
    pdfDoc.setStrokeColor([66, 133, 244])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(kpiX, kpiY, kpiW, kpiH)
    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor([66, 133, 244])
    pdfDoc.drawText("REVENUE", kpiX + 10, kpiY + kpiH - 15)
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("$2.4M", kpiX + 10, kpiY + 15)

    # Card 2
    kpiX += kpiW + 15
    pdfDoc.setFillColor([220, 245, 220])
    pdfDoc.setStrokeColor([52, 168, 83])
    pdfDoc.drawFilledRect(kpiX, kpiY, kpiW, kpiH)
    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor([52, 168, 83])
    pdfDoc.drawText("GROWTH", kpiX + 10, kpiY + kpiH - 15)
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("+24%", kpiX + 10, kpiY + 15)

    # Card 3
    kpiX += kpiW + 15
    pdfDoc.setFillColor([255, 240, 220])
    pdfDoc.setStrokeColor([255, 109, 0])
    pdfDoc.drawFilledRect(kpiX, kpiY, kpiW, kpiH)
    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor([255, 109, 0])
    pdfDoc.drawText("CUSTOMERS", kpiX + 10, kpiY + kpiH - 15)
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("12,450", kpiX + 10, kpiY + 15)

    # Chart
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Quarterly Revenue Trend", 72, 620)

    chartData = [
        :labels = ["Q1", "Q2", "Q3", "Q4"],
        :values = [480, 520, 610, 680]
    ]
    pdfDoc.drawBarChart(chartData, 72, 350, 450, 240, [
        :showValues = true,
        :colors = [[66,133,244], [66,133,244], [66,133,244], [52,168,83]]
    ])

    # Summary table
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("Department Performance", 72, 310)

    deptData = [
        ["Department", "Revenue", "Target", "Status"],
        ["Engineering", "$890K", "$800K", "Exceeded"],
        ["Sales", "$720K", "$700K", "Exceeded"],
        ["Marketing", "$340K", "$400K", "Below"],
        ["Support", "$450K", "$450K", "On Target"]
    ]

    pdfDoc.drawTable(deptData, 72, 295, [130, 110, 110, 118], [
        :headerBg = [33, 37, 41],
        :headerFg = "white",
        :evenRowBg = [245, 245, 245],
        :fontSize = 10
    ])

    if pdfDoc.save("demo13_business.pdf")
        ? "  Created: demo13_business.pdf"
    else
        ? "  FAILED: demo13_business.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 14: Letter Size
    # ------------------------------------------------------------------
    ? "Demo 14: Letter size page..."

    pdfDoc = new PDFWriter()
    pdfDoc.setPageSize(PDF_LETTER)
    pdfDoc.setTitle("US Letter Size")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("US Letter Size (8.5 x 11 in)", 72, 720)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("This document uses US Letter page size (612 x 792 points).", 72, 690)
    pdfDoc.drawText("The default page size is A4 (595.28 x 841.89 points).", 72, 670)

    if pdfDoc.save("demo14_letter.pdf")
        ? "  Created: demo14_letter.pdf"
    else
        ? "  FAILED: demo14_letter.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 15: Quick PDF Function
    # ------------------------------------------------------------------
    ? "Demo 15: Quick PDF function..."

    quickPDF("demo15_quick.pdf", "Quick Document", [
        [:title = "Quick PDF Generation", :body = "This PDF was created using the quickPDF function. It provides a simple way to create basic documents with minimal code."],
        [:title = "Second Page", :body = "The quick function supports multiple pages. Each page can have a title and body text."]
    ])
    ? "  Created: demo15_quick.pdf"

    # ------------------------------------------------------------------
    ? ""
    ? "=============================================="
    ? "   All demos completed!"
    ? "=============================================="
    ? ""
    ? "Created files:"
    ? "  1.  demo1_hello.pdf - Hello World"
    ? "  2.  demo2_fonts.pdf - Fonts and colors"
    ? "  3.  demo3_paragraphs.pdf - Paragraphs and alignment"
    ? "  4.  demo4_shapes.pdf - Shapes and drawing"
    ? "  5.  demo5_tables.pdf - Tables"
    ? "  6.  demo6_lists.pdf - Bullet and numbered lists"
    ? "  7.  demo7_multipage.pdf - Multiple pages"
    ? "  8.  demo8_headers.pdf - Headers, footers, page numbers"
    ? "  9.  demo9_bar_chart.pdf - Bar chart"
    ? "  10. demo10_pie_chart.pdf - Pie chart"
    ? "  11. demo11_watermark.pdf - Watermark"
    ? "  12. demo12_landscape.pdf - Landscape orientation"
    ? "  13. demo13_business.pdf - Complete business report"
    ? "  14. demo14_letter.pdf - US Letter page size"
    ? "  15. demo15_quick.pdf - Quick function"
    ? ""
    ? "Open these files in any PDF viewer."

demo_arabic.ring#

samples/UsingPDFLib/demo_arabic.ring
samples/UsingPDFLib/demo_arabic.ring
/*
    PDFLib - Arabic Text Demo
    =========================
    Demonstrates Arabic text rendering with:
    - Contextual letter shaping (isolated/initial/medial/final)
    - Right-to-left text layout
    - Mixed Arabic/English text
    - Arabic paragraphs with word wrapping   
*/

load "pdflib.ring"

func main

    ? "=============================================="
    ? "   PDFLib - Arabic Text Demo"
    ? "=============================================="
    ? ""

    arabicFontFile = "font/arial.ttf"

    ? "Using font: " + arabicFontFile
    ? ""

    # ------------------------------------------------------------------
    # Demo 1: Basic Arabic Text
    # ------------------------------------------------------------------
    ? "Demo 1: Basic Arabic text..."

    pdf = new PDFWriter()
    pdf.setTitle("Arabic Text Demo")
    pdf.setAuthor("RingPDFLib")

    # Load Arabic font
    pdf.loadArabicFont(arabicFontFile, "Arabic")

    # Title bar
    pdf.setFillColor([0, 100, 60])
    pdf.drawFilledRectNoStroke(0, 790, 595.28, 52)

    pdf.setFont(PDF_HELVETICA_BOLD, 22)
    pdf.setTextColor("white")
    pdf.drawText("RingPDFLib - Arabic Text Support", 72, 812)

    pdf.setFont(PDF_HELVETICA, 11)
    pdf.drawTextRight("Pure Ring Implementation", 523, 796)

    # Section 1: Basic Arabic Words
    pdf.setFont(PDF_HELVETICA_BOLD, 16)
    pdf.setTextColor([0, 100, 60])
    pdf.drawText("1. Basic Arabic Text", 72, 750)

    pdf.setStrokeColor([0, 100, 60])
    pdf.setLineWidth(2)
    pdf.drawLine(72, 743, 300, 743)

    # Arabic text samples
    pdf.setFont("Arabic", 28)
    pdf.setTextColor("black")

    # "Bismillah" (In the name of God)
    pdf.drawArabicText("بسم الله الرحمن الرحيم", 523, 700)

    # "Hello World"
    pdf.setFont("Arabic", 24)
    pdf.drawArabicText("مرحبا بالعالم", 523, 660)

    # "Ring Programming Language"
    pdf.drawArabicText("لغة البرمجة رينج", 523, 625)

    # "King Saud University"
    pdf.drawArabicText("جامعة الملك سعود", 523, 590)

    # English label
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Bismillah al-Rahman al-Rahim", 72, 700)
    pdf.drawText("Marhaba bil-Alam (Hello World)", 72, 660)
    pdf.drawText("Ring Programming Language", 72, 625)
    pdf.drawText("King Saud University", 72, 590)

    # Section 2: Letter Forms Demonstration
    pdf.setFont(PDF_HELVETICA_BOLD, 16)
    pdf.setTextColor([0, 100, 60])
    pdf.drawText("2. Contextual Letter Shaping", 72, 540)

    pdf.setStrokeColor([0, 100, 60])
    pdf.setLineWidth(2)
    pdf.drawLine(72, 533, 340, 533)

    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Arabic letters change shape based on position:", 72, 515)
    pdf.drawText("Isolated - Initial - Medial - Final", 72, 500)

    # Show different words that demonstrate shaping
    pdf.setFont("Arabic", 22)
    pdf.setTextColor("black")

    # "Muhammad" - shows medial/initial/final forms
    pdf.drawArabicText("محمود", 523, 470)
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Mahmoud", 72, 470)

    # "Abdullah" 
    pdf.setFont("Arabic", 22)
    pdf.setTextColor("black")
    pdf.drawArabicText("فايد", 523, 440)
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Fayed", 72, 440)

    # "Computer Science"
    pdf.setFont("Arabic", 22)
    pdf.setTextColor("black")
    pdf.drawArabicText("علوم الحاسب", 523, 410)
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Computer Science", 72, 410)

    # "Artificial Intelligence"
    pdf.setFont("Arabic", 22)
    pdf.setTextColor("black")
    pdf.drawArabicText("الذكاء الاصطناعي", 523, 380)
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Artificial Intelligence", 72, 380)

    # "Research and Development"
    pdf.setFont("Arabic", 22)
    pdf.setTextColor("black")
    pdf.drawArabicText("البحث والتطوير", 523, 350)
    pdf.setFont(PDF_HELVETICA, 10)
    pdf.setTextColor("gray")
    pdf.drawText("Research and Development", 72, 350)

    # Section 3: Arabic Paragraph
    pdf.setFont(PDF_HELVETICA_BOLD, 16)
    pdf.setTextColor([0, 100, 60])
    pdf.drawText("3. Arabic Paragraph (RTL Word Wrap)", 72, 300)

    pdf.setStrokeColor([0, 100, 60])
    pdf.setLineWidth(2)
    pdf.drawLine(72, 293, 380, 293)

    # Background for paragraph
    pdf.setFillColor([250, 248, 240])
    pdf.setStrokeColor([200, 190, 170])
    pdf.setLineWidth(1)
    pdf.drawFilledRect(72, 130, 451, 150)

    pdf.setFont("Arabic", 18)
    pdf.setTextColor([40, 40, 40])
    pdf.drawArabicParagraph("لغة البرمجة رينج هي لغة برمجة حديثة وسهلة التعلم تم تصميمها لتكون بسيطة وقوية في نفس الوقت وتدعم البرمجة الكائنية والبرمجة الوظيفية وتوفر مكتبات متعددة للتطوير", 523, 265, 441, 30)

    # Footer note
    pdf.setFont(PDF_HELVETICA, 9)
    pdf.setTextColor("gray")
    pdf.drawTextCentered("Generated by RingPDFLib with pure Ring Arabic text support", 297.64, 100)

    if pdf.save("demo_arabic_text.pdf")
        ? "  Created: demo_arabic_text.pdf"
    else
        ? "  FAILED: demo_arabic_text.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 2: Arabic + English Mixed Document
    # ------------------------------------------------------------------
    ? "Demo 2: Mixed Arabic/English document..."

    pdf = new PDFWriter()
    pdf.setTitle("Mixed Language Document")
    pdf.loadArabicFont(arabicFontFile, "Arabic")

    # Header
    pdf.setFillColor([25, 50, 100])
    pdf.drawFilledRectNoStroke(0, 790, 595.28, 52)

    # Draw English and Arabic title halves separately
    pdf.setFont(PDF_HELVETICA_BOLD, 20)
    pdf.setTextColor("white")
    pdf.drawTextCentered("Research Summary", 200, 810)

    pdf.setFont("Arabic", 22)
    pdf.setTextColor("white")
    pdf.drawArabicText("ملخص البحث", 460, 810)

    # Left column: English
    pdf.setFont(PDF_HELVETICA_BOLD, 14)
    pdf.setTextColor([25, 50, 100])
    pdf.drawText("Abstract", 72, 750)

    pdf.setStrokeColor([25, 50, 100])
    pdf.setLineWidth(1.5)
    pdf.drawLine(72, 744, 160, 744)

    pdf.setFont(PDF_HELVETICA, 11)
    pdf.setTextColor("black")
    curY = pdf.drawParagraph("This paper presents a novel approach to developing Terminal User Interface (TUI) frameworks using prompt-driven development methodology with large language models.", 72, 725, 200, 15)
    curY -= 10
    curY = pdf.drawParagraph("The Ring programming language serves as the implementation platform, demonstrating the effectiveness of AI-assisted software development.", 72, curY, 200, 15)

    # Right column: Arabic
    pdf.setFont("Arabic", 16)
    pdf.setTextColor([25, 50, 100])
    pdf.drawArabicText("الملخص", 523, 750)

    pdf.setStrokeColor([25, 50, 100])
    pdf.drawLine(523, 744, 470, 744)

    pdf.setFont("Arabic", 14)
    pdf.setTextColor("black")
    curY2 = pdf.drawArabicParagraph("يقدم هذا البحث منهجية جديدة لتطوير واجهات المستخدم النصية باستخدام التطوير الموجه بالأوامر مع نماذج اللغة الكبيرة", 523, 722, 200, 22)
    curY2 -= 10
    curY2 = pdf.drawArabicParagraph("تعتبر لغة البرمجة رينج منصة التنفيذ الرئيسية لهذا المشروع", 523, curY2, 200, 22)

    # Divider
    minY = curY
    if curY2 < minY minY = curY2 ok
    minY -= 20

    pdf.setStrokeColor([200, 200, 200])
    pdf.setLineWidth(0.5)
    pdf.drawLine(297, 750, 297, minY)

    # Keywords section
    minY -= 20
    pdf.setFont(PDF_HELVETICA_BOLD, 12)
    pdf.setTextColor([25, 50, 100])
    pdf.drawText("Keywords:", 72, minY)

    pdf.setFont(PDF_HELVETICA, 11)
    pdf.setTextColor("black")
    pdf.drawText("Ring Language, TUI, Prompt-Driven Development, AI", 155, minY)

    pdf.setFont("Arabic", 14)
    pdf.setTextColor([25, 50, 100])
    pdf.drawArabicText("الكلمات المفتاحية:", 523, minY)

    pdf.setFont("Arabic", 13)
    pdf.setTextColor("black")
    pdf.drawArabicText("رينج، واجهة نصية، ذكاء اصطناعي", 523, minY - 22)

    # Table with bilingual content
    minY -= 70
    pdf.setFont(PDF_HELVETICA_BOLD, 14)
    pdf.setTextColor([25, 50, 100])
    pdf.drawText("Project Details", 72, minY)
    pdf.setFont("Arabic", 16)
    pdf.drawArabicText("تفاصيل المشروع", 523, minY)

    minY -= 10

    tableData = [
        ["Field / الحقل", "Value / القيمة"],
        ["Language / اللغة", "Ring / رينج"],
        ["Framework / الإطار", "TUI / واجهة نصية"],
        ["University / الجامعة", "King Saud / جامعة الملك سعود"],
        ["Status / الحالة", "Active / نشط"]
    ]

    curY = pdf.drawTable(tableData, 72, minY, [200, 268], [
        :headerBg = [25, 50, 100],
        :headerFg = "white",
        :evenRowBg = [240, 245, 255],
        :rowHeight = 25,
        :fontSize = 11,
        :arabicFont = "Arabic"
    ])

    # Section: Pure Arabic Table
    curY -= 30
    pdf.setFont(PDF_HELVETICA_BOLD, 14)
    pdf.setTextColor([25, 50, 100])
    pdf.drawText("Pure Arabic Table", 72, curY)
    pdf.setFont("Arabic", 16)
    pdf.drawArabicText("جدول عربي", 523, curY)

    curY -= 10

    arabicTableData = [
        ["الحقل", "القيمة"],
        ["اللغة", "رينج"],
        ["الإطار", "واجهة نصية"],
        ["الجامعة", "جامعة الملك سعود"],
        ["الحالة", "نشط"],
        ["المدينة", "الرياض"]
    ]

    curY = pdf.drawTable(arabicTableData, 72, curY, [200, 268], [
        :headerBg = [25, 50, 100],
        :headerFg = "white",
        :evenRowBg = [240, 245, 255],
        :rowHeight = 25,
        :fontSize = 11,
        :arabicFont = "Arabic"
    ])

    if pdf.save("demo_arabic_mixed.pdf")
        ? "  Created: demo_arabic_mixed.pdf"
    else
        ? "  FAILED: demo_arabic_mixed.pdf"
    ok

    # ------------------------------------------------------------------
    ? ""
    ? "=============================================="
    ? "   Arabic demos completed!"
    ? "=============================================="
    ? ""
    ? "Created files:"
    ? "  1. demo_arabic_text.pdf  - Basic Arabic text with shaping"
    ? "  2. demo_arabic_mixed.pdf - Mixed Arabic/English document"
    ? ""
    ? "Features demonstrated:"
    ? "  - UTF-8 Arabic text decoding"
    ? "  - Contextual letter shaping (4 forms per letter)"
    ? "  - Right-to-left text layout"
    ? "  - Arabic paragraph with word wrapping"
    ? "  - Mixed bilingual documents and tables"
    ? "  - Pure Arabic tables"
    ? "  - TrueType font embedding with CIDFont"

demo_images.ring#

samples/UsingPDFLib/demo_images.ring
samples/UsingPDFLib/demo_images.ring
/*
    PDFLib - Images Demo
    ====================
    Demonstrates embedding PNG, JPEG and BMP images in PDF
*/

load "pdflib.ring"

C_IMAGE_TEST1 = "images/test1.png"
C_IMAGE_TEST2 = "images/test2.jpg"
C_IMAGE_TEST3 = "images/test3.bmp"

func main

    ? "=============================================="
    ? "   PDFLib - Images Demo"
    ? "=============================================="
    ? ""

    # Check which test images exist
    img1Exists = fexists(C_IMAGE_TEST1)
    img2Exists = fexists(C_IMAGE_TEST2)
    img3Exists = fexists(C_IMAGE_TEST3)

    ? "Image files found:"
    if img1Exists ? "  [OK]  images/test1.png" else ? "  [--]  images/test1.png not found" ok
    if img2Exists ? "  [OK]  images/test2.jpg" else ? "  [--]  images/test2.jpg not found" ok
    if img3Exists ? "  [OK]  images/test3.bmp" else ? "  [--]  images/test3.bmp not found" ok
    ? ""

    # ------------------------------------------------------------------
    # Demo 1: Single Image Per Page (Gallery Style)
    # ------------------------------------------------------------------
    ? "Demo 1: Image gallery..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Image Gallery")
    pdfDoc.setAuthor("RingPDFLib")
    pdfDoc.enablePageNumbers()

    # === Page 1: PNG Image ===

    # Title bar
    pdfDoc.setFillColor([41, 98, 255])
    pdfDoc.drawFilledRectNoStroke(0, 790, 595.28, 52)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("white")
    pdfDoc.drawText("Image Gallery", 72, 805)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawTextRight("RingPDFLib Demo", 523, 805)

    # Section
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 18)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("1. PNG Image (images/test1.png)", 72, 750)

    pdfDoc.setStrokeColor([41, 98, 255])
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 743, 350, 743)

    if img1Exists
        # Image border/frame
        pdfDoc.setFillColor([245, 245, 250])
        pdfDoc.setStrokeColor([200, 200, 210])
        pdfDoc.setLineWidth(1)
        pdfDoc.drawFilledRect(67, 387, 460, 340)
        
        # Draw the image
        pdfDoc.drawImage(C_IMAGE_TEST1, 72, 392, 450, 330)
        
        # Caption
        pdfDoc.setFont(PDF_HELVETICA_ITALIC, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Figure 1: PNG format image embedded in PDF", 297, 373)
    else
        pdfDoc.setFillColor([255, 240, 240])
        pdfDoc.setStrokeColor([220, 180, 180])
        pdfDoc.drawFilledRect(72, 500, 450, 200)
        pdfDoc.setFont(PDF_HELVETICA, 14)
        pdfDoc.setTextColor("red")
        pdfDoc.drawTextCentered("images/test1.png not found", 297, 610)
        pdfDoc.setFont(PDF_HELVETICA, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Place a PNG file named test1.png in the images folder", 297, 585)
    ok

    # Info box
    pdfDoc.setFillColor([240, 248, 255])
    pdfDoc.setStrokeColor([176, 196, 222])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(72, 260, 450, 90)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
    pdfDoc.setTextColor([41, 98, 255])
    pdfDoc.drawText("About PNG Format:", 82, 330)

    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("PNG (Portable Network Graphics) supports lossless compression,", 82, 312)
    pdfDoc.drawText("transparency (alpha channel), and is ideal for graphics, logos,", 82, 298)
    pdfDoc.drawText("screenshots, and images requiring sharp edges.", 82, 284)

    # === Page 2: JPEG Image ===
    pdfDoc.addPage()

    # Title bar
    pdfDoc.setFillColor([234, 67, 53])
    pdfDoc.drawFilledRectNoStroke(0, 790, 595.28, 52)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("white")
    pdfDoc.drawText("Image Gallery", 72, 805)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawTextRight("RingPDFLib Demo", 523, 805)

    # Section
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 18)
    pdfDoc.setTextColor([180, 30, 20])
    pdfDoc.drawText("2. JPEG Image (images/test2.jpg)", 72, 750)

    pdfDoc.setStrokeColor([234, 67, 53])
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 743, 350, 743)

    if img2Exists
        # Image frame
        pdfDoc.setFillColor([245, 245, 250])
        pdfDoc.setStrokeColor([200, 200, 210])
        pdfDoc.setLineWidth(1)
        pdfDoc.drawFilledRect(67, 387, 460, 340)
        
        # Draw the image
        pdfDoc.drawImage(C_IMAGE_TEST2, 72, 392, 450, 330)
        
        # Caption
        pdfDoc.setFont(PDF_HELVETICA_ITALIC, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Figure 2: JPEG format image embedded in PDF", 297, 373)
    else
        pdfDoc.setFillColor([255, 240, 240])
        pdfDoc.setStrokeColor([220, 180, 180])
        pdfDoc.drawFilledRect(72, 500, 450, 200)
        pdfDoc.setFont(PDF_HELVETICA, 14)
        pdfDoc.setTextColor("red")
        pdfDoc.drawTextCentered("images/test2.jpg not found", 297, 610)
        pdfDoc.setFont(PDF_HELVETICA, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Place a JPEG file named test2.jpg in the images folder", 297, 585)
    ok

    # Info box
    pdfDoc.setFillColor([255, 245, 245])
    pdfDoc.setStrokeColor([222, 180, 180])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(72, 260, 450, 90)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
    pdfDoc.setTextColor([234, 67, 53])
    pdfDoc.drawText("About JPEG Format:", 82, 330)

    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("JPEG uses lossy compression, making it ideal for photographs", 82, 312)
    pdfDoc.drawText("and complex images with smooth color gradients. Files are", 82, 298)
    pdfDoc.drawText("typically much smaller than PNG for photo content.", 82, 284)

    # === Page 3: BMP Image ===
    pdfDoc.addPage()

    # Title bar
    pdfDoc.setFillColor([52, 168, 83])
    pdfDoc.drawFilledRectNoStroke(0, 790, 595.28, 52)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("white")
    pdfDoc.drawText("Image Gallery", 72, 805)

    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.drawTextRight("RingPDFLib Demo", 523, 805)

    # Section
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 18)
    pdfDoc.setTextColor([30, 120, 50])
    pdfDoc.drawText("3. BMP Image (images/test3.bmp)", 72, 750)

    pdfDoc.setStrokeColor([52, 168, 83])
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 743, 350, 743)

    if img3Exists
        # Image frame
        pdfDoc.setFillColor([245, 245, 250])
        pdfDoc.setStrokeColor([200, 200, 210])
        pdfDoc.setLineWidth(1)
        pdfDoc.drawFilledRect(67, 387, 460, 340)
        
        # Draw the image
        pdfDoc.drawImage(C_IMAGE_TEST3, 72, 392, 450, 330)
        
        # Caption
        pdfDoc.setFont(PDF_HELVETICA_ITALIC, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Figure 3: BMP format image embedded in PDF", 297, 373)
    else
        pdfDoc.setFillColor([255, 240, 240])
        pdfDoc.setStrokeColor([220, 180, 180])
        pdfDoc.drawFilledRect(72, 500, 450, 200)
        pdfDoc.setFont(PDF_HELVETICA, 14)
        pdfDoc.setTextColor("red")
        pdfDoc.drawTextCentered("images/test3.bmp not found", 297, 610)
        pdfDoc.setFont(PDF_HELVETICA, 11)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("Place a BMP file named test3.bmp in the images folder", 297, 585)
    ok

    # Info box
    pdfDoc.setFillColor([240, 255, 240])
    pdfDoc.setStrokeColor([180, 220, 180])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(72, 260, 450, 90)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
    pdfDoc.setTextColor([52, 168, 83])
    pdfDoc.drawText("About BMP Format:", 82, 330)

    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("BMP (Bitmap) is an uncompressed image format native to Windows.", 82, 312)
    pdfDoc.drawText("It stores raw pixel data without compression, resulting in larger", 82, 298)
    pdfDoc.drawText("file sizes but preserving exact pixel values.", 82, 284)

    if pdfDoc.save("demo_images_gallery.pdf")
        ? "  Created: demo_images_gallery.pdf"
    else
        ? "  FAILED: demo_images_gallery.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 2: Multiple Images on One Page
    # ------------------------------------------------------------------
    ? "Demo 2: Multiple images on one page..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Multiple Images Layout")

    # Title
    pdfDoc.setFillColor([33, 37, 41])
    pdfDoc.drawFilledRectNoStroke(0, 795, 595.28, 47)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("white")
    pdfDoc.drawTextCentered("Multiple Images - Side by Side", 297.64, 810)

    # Row 1 - Two images side by side
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Row 1: PNG and JPEG Side by Side", 72, 755)

    pdfDoc.setStrokeColor([200, 200, 200])
    pdfDoc.setLineWidth(0.5)

    if img1Exists
        # Left image frame
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.drawFilledRect(72, 575, 220, 165)
        pdfDoc.drawImage(C_IMAGE_TEST1, 75, 578, 214, 159)
    ok

    if img2Exists
        # Right image frame
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.drawFilledRect(310, 575, 220, 165)
        pdfDoc.drawImage(C_IMAGE_TEST2, 313, 578, 214, 159)
    ok

    pdfDoc.setFont(PDF_HELVETICA, 9)
    pdfDoc.setTextColor("gray")
    if img1Exists pdfDoc.drawTextCentered(C_IMAGE_TEST1, 182, 562) ok
    if img2Exists pdfDoc.drawTextCentered(C_IMAGE_TEST2, 420, 562) ok

    # Row 2 - BMP image centered
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Row 2: BMP Image Centered", 72, 535)

    if img3Exists
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.drawFilledRect(148, 345, 300, 175)
        pdfDoc.drawImage(C_IMAGE_TEST3, 151, 348, 294, 169)
        
        pdfDoc.setFont(PDF_HELVETICA, 9)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered(C_IMAGE_TEST3, 297, 332)
    ok

    # Row 3 - Three thumbnails
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 14)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Row 3: Three Thumbnails", 72, 310)

    thumbW = 135
    thumbH = 100
    thumbY = 190
    gap = 22

    if img1Exists
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.drawFilledRect(72, thumbY, thumbW, thumbH)
        pdfDoc.drawImage(C_IMAGE_TEST1, 75, thumbY + 3, thumbW - 6, thumbH - 6)
        pdfDoc.setFont(PDF_HELVETICA, 8)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("PNG", 72 + thumbW / 2, thumbY - 12)
    ok

    if img2Exists
        thX = 72 + thumbW + gap
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.drawFilledRect(thX, thumbY, thumbW, thumbH)
        pdfDoc.drawImage(C_IMAGE_TEST2, thX + 3, thumbY + 3, thumbW - 6, thumbH - 6)
        pdfDoc.setFont(PDF_HELVETICA, 8)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("JPEG", thX + thumbW / 2, thumbY - 12)
    ok

    if img3Exists
        thX = 72 + (thumbW + gap) * 2
        pdfDoc.setFillColor([248, 248, 248])
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.drawFilledRect(thX, thumbY, thumbW, thumbH)
        pdfDoc.drawImage(C_IMAGE_TEST3, thX + 3, thumbY + 3, thumbW - 6, thumbH - 6)
        pdfDoc.setFont(PDF_HELVETICA, 8)
        pdfDoc.setTextColor("gray")
        pdfDoc.drawTextCentered("BMP", thX + thumbW / 2, thumbY - 12)
    ok

    # Format comparison note
    pdfDoc.setFillColor([255, 255, 240])
    pdfDoc.setStrokeColor([220, 200, 150])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(72, 80, 450, 80)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
    pdfDoc.setTextColor([130, 100, 20])
    pdfDoc.drawText("Supported Image Formats:", 82, 142)

    pdfDoc.setFont(PDF_HELVETICA, 10)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("JPEG (.jpg) - Best for photos, small file size, lossy compression", 82, 125)
    pdfDoc.drawText("PNG  (.png) - Best for graphics/logos, lossless, supports transparency", 82, 110)
    pdfDoc.drawText("BMP  (.bmp) - Uncompressed, large file size, exact pixel data", 82, 95)

    if pdfDoc.save("demo_images_layout.pdf")
        ? "  Created: demo_images_layout.pdf"
    else
        ? "  FAILED: demo_images_layout.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 3: Image with Text Wrap Around
    # ------------------------------------------------------------------
    ? "Demo 3: Image with text flow..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Image with Text")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 26)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Travel Magazine", 72, 760)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 752, 523, 752)

    # Lead paragraph
    pdfDoc.setFont(PDF_HELVETICA, 12)
    pdfDoc.setTextColor("black")

    curY = pdfDoc.drawParagraph("Welcome to our monthly travel feature. In this issue we explore some of the most breathtaking destinations around the world and share our favorite photographs from recent journeys.", 72, 730, 451, 16)
    curY -= 20

    # Image on the right with text on left
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Featured Destination", 72, curY)
    curY -= 20

    if img1Exists
        # Place image on the right
        imgW = 200
        imgH = 150
        imgX = 323
        imgY = curY - imgH
        
        pdfDoc.setFillColor([240, 240, 240])
        pdfDoc.setStrokeColor([180, 180, 180])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawFilledRect(imgX - 3, imgY - 3, imgW + 6, imgH + 6)
        pdfDoc.drawImage(C_IMAGE_TEST1, imgX, imgY, imgW, imgH)
        
        # Text flows beside the image (narrower width)
        pdfDoc.setFont(PDF_HELVETICA, 11)
        pdfDoc.setTextColor([60, 60, 60])
        textWidth = imgX - 72 - 15
        curY = pdfDoc.drawParagraph("The ancient city offers a stunning blend of history and modern culture. Walking through its cobblestone streets, visitors are transported back in time to an era of magnificent architecture and rich traditions.", 72, curY, textWidth, 15)
        curY -= 5
        curY = pdfDoc.drawParagraph("Local markets overflow with colorful textiles, aromatic spices, and handcrafted goods that tell stories of generations of artisans.", 72, curY, textWidth, 15)
        
        # After image, full-width text
        if curY > imgY
            curY = imgY - 15
        ok
    else
        curY -= 10
    ok

    pdfDoc.setFont(PDF_HELVETICA, 11)
    pdfDoc.setTextColor([60, 60, 60])
    curY = pdfDoc.drawParagraph("Beyond the historic center, natural wonders await. Crystal-clear waters and dramatic mountain landscapes make this region a paradise for nature lovers and adventure seekers alike. Whether hiking through dense forests or relaxing on sun-drenched beaches, every moment offers a new discovery.", 72, curY, 451, 15)
    curY -= 25

    # Second section with image on the left
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Culinary Journey", 72, curY)
    curY -= 20

    if img2Exists
        imgW = 180
        imgH = 130
        imgX = 72
        imgY = curY - imgH
        
        pdfDoc.setFillColor([240, 240, 240])
        pdfDoc.setStrokeColor([180, 180, 180])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawFilledRect(imgX - 3, imgY - 3, imgW + 6, imgH + 6)
        pdfDoc.drawImage(C_IMAGE_TEST2, imgX, imgY, imgW, imgH)
        
        # Text flows to the right of image
        pdfDoc.setFont(PDF_HELVETICA, 11)
        pdfDoc.setTextColor([60, 60, 60])
        textX = imgX + imgW + 15
        textWidth = 523 - textX
        curY = pdfDoc.drawParagraph("No visit is complete without sampling the local cuisine. From street food vendors serving sizzling specialties to elegant restaurants offering fusion dishes that blend traditional recipes with contemporary techniques.", textX, curY, textWidth, 15)
        curY -= 5
        curY = pdfDoc.drawParagraph("The seafood markets are particularly renowned, offering the freshest catch prepared with techniques passed down through centuries.", textX, curY, textWidth, 15)
        
        if curY > imgY
            curY = imgY - 15
        ok
    else
        curY -= 10
    ok

    pdfDoc.setFont(PDF_HELVETICA, 11)
    pdfDoc.setTextColor([60, 60, 60])
    curY = pdfDoc.drawParagraph("We hope these images and stories inspire your next adventure. Travel opens our minds, enriches our souls, and connects us with people and places that forever change our perspective on the world.", 72, curY, 451, 15)

    if pdfDoc.save("demo_images_text.pdf")
        ? "  Created: demo_images_text.pdf"
    else
        ? "  FAILED: demo_images_text.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 4: Image Sizes and Scaling
    # ------------------------------------------------------------------
    ? "Demo 4: Image sizes and scaling..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Image Scaling Demo")

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 24)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Image Scaling & Sizing", 72, 760)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 752, 380, 752)

    if img2Exists
        # Small
        pdfDoc.setFont(PDF_HELVETICA_BOLD, 12)
        pdfDoc.setTextColor("black")
        pdfDoc.drawText("Small (80 x 60)", 72, 720)
        
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawRect(71, 649, 82, 62)
        pdfDoc.drawImage(C_IMAGE_TEST2, 72, 650, 80, 60)
        
        # Medium
        pdfDoc.drawText("Medium (200 x 150)", 200, 720)
        
        pdfDoc.drawRect(199, 559, 202, 152)
        pdfDoc.drawImage(C_IMAGE_TEST2, 200, 560, 200, 150)
        
        # Large
        pdfDoc.drawText("Large (400 x 250)", 72, 530)
        
        pdfDoc.drawRect(71, 269, 402, 252)
        pdfDoc.drawImage(C_IMAGE_TEST2, 72, 270, 400, 250)
        
        # Stretched
        pdfDoc.drawText("Stretched Wide (450 x 80)", 72, 240)
        
        pdfDoc.drawRect(71, 149, 452, 82)
        pdfDoc.drawImage(C_IMAGE_TEST2, 72, 150, 450, 80)

    elseif img1Exists
        pdfDoc.setFont(PDF_HELVETICA_BOLD, 12)
        pdfDoc.setTextColor("black")
        pdfDoc.drawText("Small (80 x 60)", 72, 720)
        pdfDoc.drawImage(C_IMAGE_TEST1, 72, 650, 80, 60)
        
        pdfDoc.drawText("Medium (200 x 150)", 200, 720)
        pdfDoc.drawImage(C_IMAGE_TEST1, 200, 560, 200, 150)
        
        pdfDoc.drawText("Large (400 x 250)", 72, 530)
        pdfDoc.drawImage(C_IMAGE_TEST1, 72, 270, 400, 250)
    else
        pdfDoc.setFont(PDF_HELVETICA, 14)
        pdfDoc.setTextColor("red")
        pdfDoc.drawTextCentered("No test images found for scaling demo", 297, 500)
    ok

    if pdfDoc.save("demo_images_scaling.pdf")
        ? "  Created: demo_images_scaling.pdf"
    else
        ? "  FAILED: demo_images_scaling.pdf"
    ok

    # ------------------------------------------------------------------
    # Demo 5: Photo Report with All Three Formats
    # ------------------------------------------------------------------
    ? "Demo 5: Photo report..."

    pdfDoc = new PDFWriter()
    pdfDoc.setTitle("Photo Report")
    pdfDoc.setAuthor("RingPDFLib")
    pdfDoc.enablePageNumbers()
    pdfDoc.setHeader("Photo Report - Confidential", PDF_ALIGN_LEFT)

    # === Cover Page ===
    pdfDoc.setFillColor([25, 25, 50])
    pdfDoc.drawFilledRectNoStroke(0, 0, 595.28, 841.89)

    # Decorative line
    pdfDoc.setFillColor([66, 133, 244])
    pdfDoc.drawFilledRectNoStroke(60, 440, 475, 4)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 40)
    pdfDoc.setTextColor("white")
    pdfDoc.drawTextCentered("Photo Report", 297.64, 520)

    pdfDoc.setFont(PDF_HELVETICA, 18)
    pdfDoc.setTextColor([150, 180, 255])
    pdfDoc.drawTextCentered("Image Format Comparison", 297.64, 470)

    pdfDoc.setFont(PDF_HELVETICA, 14)
    pdfDoc.setTextColor([180, 180, 200])
    pdfDoc.drawTextCentered("Generated by RingPDFLib", 297.64, 370)
    pdfDoc.drawTextCentered("Demonstrating PNG, JPEG, and BMP Support", 297.64, 345)

    # === Page 2: Comparison Table + Images ===
    pdfDoc.addPage()

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Format Comparison", 72, 750)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 742, 320, 742)

    # Comparison table
    compData = [
        ["Property", "JPEG", "PNG", "BMP"],
        ["Compression", "Lossy", "Lossless", "None"],
        ["File Size", "Small", "Medium", "Large"],
        ["Transparency", "No", "Yes (Alpha)", "No"],
        ["Best For", "Photos", "Graphics", "Raw Data"],
        ["Color Depth", "24-bit", "24/32-bit", "24-bit"],
        ["Extension", ".jpg / .jpeg", ".png", ".bmp"]
    ]

    curY = pdfDoc.drawTable(compData, 72, 725, [100, 118, 125, 125], [
        :headerBg = [33, 37, 41],
        :headerFg = "white",
        :evenRowBg = [240, 245, 250],
        :rowHeight = 22,
        :fontSize = 10
    ])

    curY -= 60

    # Show all three images side by side
    pdfDoc.setFont(PDF_HELVETICA_BOLD, 16)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Sample Images", 72, curY)
    curY -= 60

    imgW = 140
    imgH = 105

    # PNG
    pdfDoc.setFillColor([230, 240, 255])
    pdfDoc.setStrokeColor([100, 140, 220])
    pdfDoc.setLineWidth(1)
    pdfDoc.drawFilledRect(72, curY - imgH - 5, imgW + 10, imgH + 30)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 9)
    pdfDoc.setTextColor([41, 98, 255])
    pdfDoc.drawTextCentered("PNG", 72 + (imgW + 10) / 2, curY + 10)

    if img1Exists
        pdfDoc.drawImage(C_IMAGE_TEST1, 77, curY - imgH, imgW, imgH)
    ok

    # JPEG
    startX2 = 72 + imgW + 20
    pdfDoc.setFillColor([255, 235, 230])
    pdfDoc.setStrokeColor([220, 100, 80])
    pdfDoc.drawFilledRect(startX2, curY - imgH - 5, imgW + 10, imgH + 30)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 9)
    pdfDoc.setTextColor([234, 67, 53])
    pdfDoc.drawTextCentered("JPEG", startX2 + (imgW + 10) / 2, curY + 10)

    if img2Exists
        pdfDoc.drawImage(C_IMAGE_TEST2, startX2 + 5, curY - imgH, imgW, imgH)
    ok

    # BMP
    startX3 = startX2 + imgW + 20
    pdfDoc.setFillColor([230, 255, 235])
    pdfDoc.setStrokeColor([80, 180, 100])
    pdfDoc.drawFilledRect(startX3, curY - imgH - 5, imgW + 10, imgH + 30)

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 9)
    pdfDoc.setTextColor([52, 168, 83])
    pdfDoc.drawTextCentered("BMP", startX3 + (imgW + 10) / 2, curY + 10)

    if img3Exists
        pdfDoc.drawImage(C_IMAGE_TEST3, startX3 + 5, curY - imgH, imgW, imgH)
    ok

    # === Page 3: Full Size Showcase ===
    pdfDoc.addPage()

    pdfDoc.setFont(PDF_HELVETICA_BOLD, 22)
    pdfDoc.setTextColor("navy")
    pdfDoc.drawText("Full Size Showcase", 72, 750)

    pdfDoc.setStrokeColor("navy")
    pdfDoc.setLineWidth(2)
    pdfDoc.drawLine(72, 742, 320, 742)

    pdfDoc.setFont(PDF_HELVETICA, 11)
    pdfDoc.setTextColor("black")
    pdfDoc.drawText("All three images displayed at 451 x 200 points:", 72, 720)

    curY = 690

    if img1Exists
        pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
        pdfDoc.setTextColor([41, 98, 255])
        pdfDoc.drawText(C_IMAGE_TEST1, 72, curY)
        curY -= 10
        
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawRect(71, curY - 201, 453, 202)
        pdfDoc.drawImage(C_IMAGE_TEST1, 72, curY - 200, 451, 200)
        curY -= 220
    ok

    if img2Exists
        pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
        pdfDoc.setTextColor([234, 67, 53])
        pdfDoc.drawText(C_IMAGE_TEST2, 72, curY)
        curY -= 10
        
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawRect(71, curY - 201, 453, 202)
        pdfDoc.drawImage(C_IMAGE_TEST2, 72, curY - 200, 451, 200)
        curY -= 220
    ok

    if img3Exists
        if curY < 250
            pdfDoc.addPage()
            curY = 750
        ok
        
        pdfDoc.setFont(PDF_HELVETICA_BOLD, 11)
        pdfDoc.setTextColor([52, 168, 83])
        pdfDoc.drawText(C_IMAGE_TEST3, 72, curY)
        curY -= 10
        
        pdfDoc.setStrokeColor([200, 200, 200])
        pdfDoc.setLineWidth(0.5)
        pdfDoc.drawRect(71, curY - 201, 453, 202)
        pdfDoc.drawImage(C_IMAGE_TEST3, 72, curY - 200, 451, 200)
    ok

    if pdfDoc.save("demo_images_report.pdf")
        ? "  Created: demo_images_report.pdf"
    else
        ? "  FAILED: demo_images_report.pdf"
    ok

    # ------------------------------------------------------------------
    ? ""
    ? "=============================================="
    ? "   All image demos completed!"
    ? "=============================================="
    ? ""
    ? "Created files:"
    ? "  1. demo_images_gallery.pdf  - One image per page gallery"
    ? "  2. demo_images_layout.pdf   - Multiple images on one page"
    ? "  3. demo_images_text.pdf     - Images with text flow"
    ? "  4. demo_images_scaling.pdf  - Different sizes and scaling"
    ? "  5. demo_images_report.pdf   - Full photo report"
    ? ""
    ? "Supported image formats: JPEG (.jpg), PNG (.png), BMP (.bmp)"
PDFLib - PDF generation for Ring, made with ringdoc.