{"library":"pydyf","code":"import pydyf\n\ndocument = pydyf.PDF()\ndraw = pydyf.Stream()\n\n# Set the drawing color to red\ndraw.set_color_rgb(1.0, 0.0, 0.0)\n# Draw a rectangle\ndraw.rectangle(10, 10, 100, 50)\ndraw.fill() # Fill the rectangle\n\n# Add a page with the drawing stream\ndocument.add_page(pydyf.Dictionary({\n    'Type': '/Page',\n    'MediaBox': pydyf.Array([0, 0, 200, 200]),\n    'Contents': draw,\n}))\n\n# Write the PDF to a file\nwith open('output.pdf', 'wb') as f:\n    document.write(f)","lang":"python","description":"This example demonstrates how to create a basic PDF document, draw a red rectangle on a page, and save it to a file using pydyf.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}