Branch
Hash :
76e50487
Author :
Thomas de Grivel
Date :
2025-12-08T16:08:52
wip asan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
quote require PDF.Write
require PDF.Write
quote doc = PDF.Write.new_file("write.pdf")
doc = PDF.Write.new_file("write.pdf")
# Assets
quote image = PDF.Write.image_from_file(doc, "image.jpeg")
image = PDF.Write.image_from_file(doc, "image.jpeg")
quote font = PDF.Write.font_from_file(doc, "font.ttf")
font = PDF.Write.font_from_file(doc, "font.ttf")
# A4
quote a4 = %PDF.Rect{w: (F32) 210, h: (F32) 297}
a4 = %PDF.Rect{w: (F32) 210, h: (F32) 297}
# Page 1
quote page1 = PDF.Write.Page.new(doc, a4)
page1 = PDF.Write.Page.new(doc, a4)
# Texte
quote x = (F32) 100
x = (F32) 100
quote y = (F32) 200
y = (F32) 200
quote font_size = (F32) 12
font_size = (F32) 12
quote PDF.Write.Page.set_color_rgb(page1, (F32) 0, (F32) 0, (F32) 0)
PDF.Write.Page.set_color_rgb(page1, (F32) 0, (F32) 0, (F32) 0)
quote PDF.Write.Page.text(page1, x, y, font, font_size, "Test 123\nPlop")
PDF.Write.Page.text(page1, x, y, font, font_size, "Test 123\nPlop")
# Image
quote x = (F32) 10
x = (F32) 10
quote y = (F32) 50
y = (F32) 50
quote PDF.Write.Page.image(page1, x, y, image)
PDF.Write.Page.image(page1, x, y, image)
# Rectangle
quote rect = %PDF.Rect{x: (F32) 10,
y: (F32) 10,
w: (F32) 267,
h: (F32) 10}
rect = %PDF.Rect{x: (F32) 10,
y: (F32) 10,
w: (F32) 267,
h: (F32) 10}
quote PDF.Write.Page.set_color_rgb(page1, (F32) 0, (F32) 0, (F32) 0)
PDF.Write.Page.set_color_rgb(page1, (F32) 0, (F32) 0, (F32) 0)
quote PDF.Write.Page.rectangle(page1, rect)
PDF.Write.Page.rectangle(page1, rect)
# write
quote PDF.Write.add_page(doc, page1)
PDF.Write.add_page(doc, page1)
# clean
quote PDF.Write.Page.delete(page1)
PDF.Write.Page.delete(page1)
quote PDF.Write.close(doc)
PDF.Write.close(doc)
quote PDF.Write.delete(doc)
PDF.Write.delete(doc)