Skip to content

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.

The finished Dunder Mifflin employee badge, with photo, name, position and a MANAGER ribbon

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.

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.
  • isManager needs 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.
  1. 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.

  2. 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.

  1. Pick Add image box and draw a square, about 300 × 300, centered and overlapping the bottom of the band.

  2. Click Choose image, open the Variable tab, and pick photo. The box now shows the default photo, with a badge naming the variable.

  3. 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.
  1. Draw a text box under the photo, the width of the badge minus the margins (about 680 × 130).

  2. Click Variable (⚡) in the text bar and pick firstName. Press Enter for a new paragraph, and insert lastName.

  3. 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.

  4. Draw a second text box below, insert position, and set it in 32, grey, centered.

  1. Pick Add group and draw a band across the bottom of the badge, about 800 × 120.

  2. Draw a text box inside the group (drawing over a group puts the shape in it) and type MANAGER in Montserrat, 56, bold, white.

  3. 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.
  4. At the end of the group bar, click Show (the eye) and pick isManager under 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.

  1. 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.

  2. Change its text to STAFF, its fill to a light tint, and its text color to your brand color.

  3. 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.

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.

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()));

This example prints the template by its code, so type BADGE in the code field next to the title.

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
  • 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 employees list (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.