"""Build a 2-page test PDF from public-domain text (Mary Shelley, Frankenstein, 1818, Letter I)."""
import pymupdf
TXT=("You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. "
"I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking. "
"I am already far north of London, and as I walk in the streets of Petersburgh, I feel a cold northern breeze play upon my cheeks, which braces my nerves and fills me with delight. "
"Do you understand this feeling? This breeze, which has travelled from the regions towards which I am advancing, gives me a foretaste of those icy climes. "
"Inspirited by this wind of promise, my daydreams become more fervent and vivid. I try in vain to be persuaded that the pole is the seat of frost and desolation; "
"it ever presents itself to my imagination as the region of beauty and delight. There, Margaret, the sun is for ever visible, its broad disk just skirting the horizon and diffusing a perpetual splendour. "
"There, for with your leave, my sister, I will put some trust in preceding navigators, there snow and frost are banished; and, sailing over a calm sea, we may be wafted to a land surpassing in wonders and in beauty every region hitherto discovered on the habitable globe.")
doc=pymupdf.open()
W,H=595,842
def chrome(p,n):
    p.insert_text((50,40),"Frankenstein (1818) - Letter I",fontsize=9,fontname="helv")
    p.insert_text((W-80,H-30),f"Page {n}",fontsize=9,fontname="helv")
p=doc.new_page(width=W,height=H); chrome(p,1)
p.insert_text((50,80),"Letter I",fontsize=18,fontname="hebo")
p.insert_text((50,100),"To Mrs. Saville, England. St. Petersburgh, Dec. 11th, 17-.",fontsize=10,fontname="heit")
words=TXT.split(); half=len(words)//2
left=" ".join(words[:half])+" ¹"; right=" ".join(words[half:])
p.insert_textbox(pymupdf.Rect(50,120,290,700),left,fontsize=10.5,fontname="tiro",align=3)
p.insert_textbox(pymupdf.Rect(305,120,545,700),right,fontsize=10.5,fontname="tiro",align=3)
p.draw_line((50,740),(200,740),width=0.5)
p.insert_textbox(pymupdf.Rect(50,745,545,790),"¹ Petersburgh: the 1818 spelling of St Petersburg, kept as in the first edition.",fontsize=8,fontname="tiro")
p=doc.new_page(width=W,height=H); chrome(p,2)
p.insert_text((50,80),"Voyage log (illustrative table)",fontsize=13,fontname="hebo")
x=[50,200,350,545]; y=[95,115,135,155,175]
for yy in y: p.draw_line((x[0],yy),(x[-1],yy),width=0.6)
for xx in x: p.draw_line((xx,y[1]),(xx,y[-1]),width=0.6)
p.draw_line((x[0],y[0]),(x[0],y[1]),width=0.6); p.draw_line((x[-1],y[0]),(x[-1],y[1]),width=0.6)
p.insert_text((260,109),"Route (merged header)",fontsize=10,fontname="hebo")
rows=[("Leg","From","To"),("1","London","Petersburgh"),("2","Petersburgh","Archangel")]
for r,row in enumerate(rows):
    for c,val in enumerate(row): p.insert_text((x[c]+6,y[r+1]+14),val,fontsize=10,fontname="hebo" if r==0 else "helv")
p.insert_textbox(pymupdf.Rect(50,200,545,260),"This paragraph is set at 7 pt to imitate a translated paragraph that was shrunk to fit the space of a shorter original sentence. "+TXT[:TXT.index("welfare")+7]+".",fontsize=7,fontname="tiro")
p.insert_textbox(pymupdf.Rect(50,280,300,360),"A line that ends in a hyphen-\nated word, as typeset books often do, tests whether the converter joins the word again.",fontsize=10.5,fontname="tiro")
doc.save("fixture.pdf"); print(doc.page_count)
