Recipe: photo, text and a condition
This recipe builds a Dunder Mifflin Scranton employee badge. Every badge shows the employee’s photo, name and position, with a MANAGER ribbon for managers and a STAFF ribbon for everyone else.
Along the way you’ll use image variables, string variables sized for their space, and conditions (the if of a template) with When true and When false.

1. Create the template
Section titled “1. Create the template”On My Templates, click New Template. Name it Badge, choose Custom and enter
800 × 1200, the proportions of a badge holder. One unit is one point in the PDF, and the
badge prints scaled to the paper.
2. Declare the variables
Section titled “2. Declare the variables”Declare the variables first, so that every picker lists them while you design. Click Variables → Add Variable for each:
| Name | Type | Required | Max length | Default |
|---|---|---|---|---|
photo |
Image | A neutral avatar picture | ||
firstName |
String | ✅ | 16 | |
lastName |
String | ✅ | 24 | |
position |
String | 32 | ||
isManager |
Boolean | Off |
- The max lengths match the room on the badge. A longer name would not fit its box, so the export refuses it with a clear error instead of printing an overflowing badge.
- The default photo is drawn when an export sends none. The editor shows it too, which helps you design around it.
isManagerneeds a default. A condition on a boolean with neither a value nor a default hides its shape both ways, and the badge would get no ribbon at all.
3. Draw the header
Section titled “3. Draw the header”-
Pick Add rectangle and draw a band across the top of the page, about 800 × 220. In the context bar, set its Fill to your brand color and clear its Stroke.
-
Draw a text box on the band, type
DUNDER MIFFLIN, and set it in Montserrat, 48, bold, white, centered. You could also put the company logo in an image box instead.
4. Add the photo
Section titled “4. Add the photo”-
Pick Add image box and draw a square, about 300 × 300, centered and overlapping the bottom of the band.
-
Click Choose image, open the Variable tab, and pick
photo. The box now shows the default photo, with a badge naming the variable. -
In the image bar, set:
- Fit: Cover, so any photo fills the square without being distorted. The alignment grid decides which part is kept, and center works for portraits;
- Radius: half the side, 150, for a round photo;
- Stroke: white, 10, for a ring that sets the photo apart from the band.
5. Write the name and position
Section titled “5. Write the name and position”-
Draw a text box under the photo, the width of the badge minus the margins (about 680 × 130).
-
Click Variable (⚡) in the text bar and pick
firstName. Press Enter for a new paragraph, and insertlastName. -
Select the first line and set it in Montserrat, 64, bold, and the second in 40. Center both. The chips take this formatting, and the values print with it.
-
Draw a second text box below, insert
position, and set it in 32, grey, centered.
6. The condition: a ribbon for managers
Section titled “6. The condition: a ribbon for managers”-
Pick Add group and draw a band across the bottom of the badge, about 800 × 120.
-
Draw a text box inside the group (drawing over a group puts the shape in it) and type
MANAGERin Montserrat, 56, bold, white. -
Select the group by clicking a free area inside it, or its row in the layers panel. In the group bar, set:
- Fill: your brand color, since a group paints its own background;
- Children layout: Stack, and the center cell of the alignment grid, so the text stays centered in the band whatever its length.
-
At the end of the group bar, click Show (the eye) and pick
isManagerunder Variables. The button now reads Show: isManager.
The condition applies to the group and everything in it. Since isManager defaults to false, the
editor draws the ribbon faded: with the default values, it would be left out of the PDF. Michael
Scott is a manager, but the template doesn’t know that yet.
7. The else: a ribbon for everyone else
Section titled “7. The else: a ribbon for everyone else”-
With the ribbon selected, press Ctrl+D to duplicate it. The copy lands 20 points lower and to the right. Press Shift+← twice and Shift+↑ twice to put it exactly over the original.
-
Change its text to
STAFF, its fill to a light tint, and its text color to your brand color. -
Click Show: isManager and pick When false. The button now reads Show: not isManager.
Each badge prints exactly one of the two ribbons, so they can share the same place.
8. Preview both cases
Section titled “8. Preview both cases”Click Preview. In the Variable Values form, upload a photo, type a name (the counters show
the max lengths), switch isManager on, and click Preview. Then go back and preview again
with isManager off, for Dwight Schrute, who is only Assistant to the Regional Manager. His
badge gets the STAFF ribbon. If you change the template in between, click Refresh to redraw
the preview.
9. Generate badges from your code
Section titled “9. Generate badges from your code”An image value is sent as a data URL: the PNG or JPEG file, base64-encoded, after
data:image/png;base64, or data:image/jpeg;base64,.
{ "photo": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…", "firstName": "Michael", "lastName": "Scott", "position": "Regional Manager", "isManager": true}import { readFile, writeFile } from 'node:fs/promises';
const photo = `data:image/jpeg;base64,${(await readFile('michael.jpg')).toString('base64')}`;
const res = await fetch('https://app.imprime.io/api/export/code/BADGE/pdf', { method: 'POST', headers: { 'x-api-key': process.env.IMPRIME_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ photo, firstName: 'Michael', lastName: 'Scott', position: 'Regional Manager', isManager: true, }),});
if (!res.ok) throw new Error(await res.text());await writeFile('badge-michael.pdf', Buffer.from(await res.arrayBuffer()));import base64, os, requests
with open("michael.jpg", "rb") as f: photo = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()
res = requests.post( "https://app.imprime.io/api/export/code/BADGE/pdf", headers={"x-api-key": os.environ["IMPRIME_API_KEY"]}, json={ "photo": photo, "firstName": "Michael", "lastName": "Scott", "position": "Regional Manager", "isManager": True, }, timeout=60,)res.raise_for_status()open("badge-michael.pdf", "wb").write(res.content)This example prints the template by its code, so type BADGE in the code field next to the
title.
Rules to remember
Section titled “Rules to remember”| Rule | Why it matters |
|---|---|
A condition shows its shape only when the boolean is exactly true (or exactly false with When false) |
"true", a string, shows nothing. Send real booleans |
| A boolean with no value and no default matches neither | Give optional booleans a default |
| Image values are PNG or JPEG data URLs | Anything else fails the export with INVALID_IMAGE_VALUE. Convert other formats before sending |
| An image variable with no value draws its default, or nothing | An empty box with a border still shows its border |
| Any shape can have a condition: a text, an image, a group, a page | Put several shapes in a group to show or hide them together |
| In a row or a column, a hidden shape takes no room | What follows moves up: see Layouts with groups |
Going further
Section titled “Going further”- Print every employee’s badge, with one request per employee as in
Generate in bulk, or all of them in one PDF, with a page repeated for each
item of an
employeeslist (see Page options). - Lay the badge out with groups instead of fixed positions, so it still fits whatever the length of the name: Layouts with groups.