from PIL import Image, ImageDraw, ImageFont
# Your answer text (shortened for example)
text = """Problem 16 – Machinery Account
W.N. 1: Depreciation & Loss on Sale
Cost of Machine: ₹1,60,000
+ Overhauling: ₹40,000
= ₹2,00,000
Depreciation:
2017: ₹20,000
2018: ₹20,000
2019: ₹10,000
Total: ₹50,000
Loss on Sale: ₹50,000
"""
# Create image
img = Image.new('RGB', (800, 600), color='white')
d = ImageDraw.Draw(img)
# Use a monospaced font (important for alignment)
font = ImageFont.truetype("cour.ttf", 16) # Use Courier New or similar
# Draw text
d.text((20, 20), text, fill=(0, 0, 0), font=font)
# Save as PNG
img.save("machinery_account_answer.png") Convert to image