Basic Help on Magazine Layout

Hi

I am new to pymupdf and not an experienced developer.

I want to create a magazine layout from an HTML file, in 3 column format with a “stand first”, image and “pull quote”. I have got the 3 columns and a “stand first”. I am trying to add an image.

This is the test code I have [direct from the docs]:

import pymupdf

MEDIABOX = pymupdf.paper_rect(“letter”)

WHERE = MEDIABOX + (36, 36, -36, -36)

# create story, let it look at script folder for resources

story = pymupdf.Story(archive=“.”)

body = story.body # access the body of its DOM

with body.add_paragraph() as para:

*# store desired content*

*para.set_font("sans-serif").set_color("blue").add_text("Hello World!")*

# another paragraph for our image:

with body.add_paragraph() as para:

*# store image in another paragraph*

*# para.add_image("world.jpg")*

*para.add_image("image.jpg")*

writer = pymupdf.DocumentWriter(“pymupdf_output_11.pdf”)

more = 1

while more:

*device = writer.begin_page(MEDIABOX)*

*more, \_ = story.place(WHERE)*

*story.draw(device)*

*writer.end_page()*

writer.close()

What I see in the pdf is:

what have i done wrong?

Welcome @dangermouse !

I’m just going to format your code a bit, I think you are using this example:

import pymupdf

MEDIABOX = pymupdf.paper_rect("letter")
WHERE = MEDIABOX + (36, 36, -36, -36)

# create story, let it look at script folder for resources
story = pymupdf.Story(archive=".")
body = story.body  # access the body of its DOM

with body.add_paragraph() as para:
    # store desired content
    para.set_font("sans-serif").set_color("blue").add_text("Hello World!")

# another paragraph for our image:
with body.add_paragraph() as para:
    # store image in another paragraph
    para.add_image("image.jpg")

writer = pymupdf.DocumentWriter("pymupdf_output11.pdf")

more = 1

while more:
    device = writer.begin_page(MEDIABOX)
    more, _ = story.place(WHERE)
    story.draw(device)
    writer.end_page()

writer.close()

Does the “image.jpg” resource exist in the same place where you run this script?