Polotno

DIRECT MAIL

Lob API + Polotno: a postcard design editor for Lob Print & Mail

Embed Polotno's design editor so your users design postcards inside your app. Polotno exports the PDF/X-1a files Lob asks for; Lob prints, adds postage and mails them.

Polotno + Lob pairs Polotno's embedded design editor SDK with Lob's Print & Mail API. Your users design postcards inside your app, your backend exports each side as a print-ready PDF and creates the postcard through Lob's API, and Lob prints it, adds the address and postage, and mails it.

The problem Lob doesn't solve

Lob covers the back half of direct mail: address verification, printing across its network of commercial printers, postage, and delivery tracking. For design, Lob gives your own team HTML templates, a Visual Editor in the Lob dashboard, and Figma and InDesign connectors. Your team builds templates with those tools and sends them from Lob. If your product lets your customers design their own mail, the editor has to live in your app.

Teams that build on Lob without a design layer usually:

  • Ask customers to upload finished PDFs, then reject the ones that ignore bleed or put artwork under the address block
  • Hand-code HTML templates and expose a few text fields
  • Spend months on an editor that knows Lob's file sizes and ink-free zone

Polotno goes in front of Lob. Customers design on a canvas sized to Lob's file, your app checks the address side before export, and your backend sends Lob a PDF/X-1a file for each side.

How the integration works

  • Design: the user picks a size (4x6, 6x9 or 6x11). Polotno loads a two-page template, front and back, at the file size Lob expects for that card.
  • Edit: the user changes text, photos and colors. Template variables hold the fields that change per recipient, such as a first name or an offer code.
  • Export: your backend fills the template once per recipient with resolveVariables and exports each side as a PDF/X-1a file with @polotno/pdf-export.
  • Order: your backend creates the postcard with POST /v1/postcards, sending the front file, the back file and the recipient's address.
  • Fulfill: Lob prints the card, adds the address block and postage, and mails it. Webhooks report each step, from postcard.created to postcard.delivered.

Prepare the print file

Lob's file guidelines ask for a 1/8 in border around the trim, so a 4 × 6 in card arrives as a 6.25 × 4.25 in file at 300 DPI. They also ask for no crop marks, no critical elements within 1/8 in of the trim, no postage marks, and files of 5 MB or less. Lob's PDF preflight checklist adds PDF/X-1a, CMYK color, flattened transparency, embedded fonts, 300 ppi images, and page boxes that are all the same size.

That last item decides how you size the canvas. Lob's own postcard templates put the trim box at the full file size, so make the Polotno page the whole 6.25 × 4.25 in file rather than the 6 × 4 in trim with bleed added. The trim then sits 1/8 in inside the page edge, so keep text at least 1/4 in from the page edge.

js
import { unitToPx } from 'polotno/utils/unit'

// Lob's 4x6 postcard file: 6.25 × 4.25 in at 300 DPI.
// Lob trims 1/8 in from every edge, so keep text 1/4 in inside the page.
const dpi = 300
const inch = (value) => unitToPx({ unit: 'in', unitVal: value, dpi })
store.setUnit({ unit: 'in', dpi })
store.setSize(inch(6.25), inch(4.25))
store.addPage() // front
store.addPage() // back

On the back, Lob prints the address block and postage in a white box, and covers anything you put under it. Lob's postcard specs give the box as 3.2835 × 2.375 in on a 4 × 6 card and 4 × 2.375 in on the larger sizes. Lob measures it 0.275 in from the right edge and 0.25 in from the bottom edge of the file, bleed included, which on this canvas is the page edge. Keep template elements out of that box, and check for overlaps before export with design validation. The direct mail donor postcards demo draws the address-side zones, warns when an element overlaps one, and keeps export off until it moves.

To send, fill the template for each recipient and export each page as its own PDF, because Lob takes the front and the back as separate files. The snippet assumes a Node backend, an ICC profile supplied as profile with its profileIdentifier, and recipients already saved in Lob's address book.

js
import { resolveVariables } from '@polotno/schema/variables'
import { jsonToPDFBytes } from '@polotno/pdf-export'

const template = store.toJSON() // saved from the editor
const pdfOptions = {
  key: POLOTNO_API_KEY,
  pdfx: 'x-1a',
  outputIntent: { profile, identifier: profileIdentifier }, // SWOP or GRACoL
}
const sidePdf = async (design, page) =>
  new Blob([await jsonToPDFBytes({ ...design, pages: [page] }, pdfOptions)], {
    type: 'application/pdf',
  })

for (const recipient of recipients) {
  const { design } = resolveVariables(template, recipient, { strict: true })
  const [front, back] = design.pages

  const body = new FormData()
  body.append('to', recipient.lobAddressId) // an adr_ id, or inline to[name], to[address_line1], … fields
  body.append('size', '4x6')
  body.append('use_type', 'marketing')
  body.append('front', await sidePdf(design, front), 'front.pdf')
  body.append('back', await sidePdf(design, back), 'back.pdf')

  await fetch('https://api.lob.com/v1/postcards', {
    method: 'POST',
    headers: {
      Authorization: `Basic ${btoa(`${LOB_API_KEY}:`)}`, // API key as username, no password
      'Idempotency-Key': recipient.id, // a retry returns the first postcard
    },
    body,
  })
}

With pdfx: 'x-1a', Polotno writes every color as CMYK, tags the file with the output profile you pass, embeds every font, and flattens any page that carries transparency into a CMYK image at 300 DPI. Pages without transparency stay vector. Lob's checklist prefers a SWOP v2 or GRACoL 2006/2013 profile. Check image resolution and the 5 MB limit on your own artwork, since both depend on what your users upload. See PDF export for the export options and units and measures for sizing pages in inches.

What Polotno handles vs. what Lob handles

Polotno (in your app)

  • Embedded postcard editor: front and back on one canvas
  • Templates at Lob's file sizes, with locked brand and address-side elements
  • Template variables for per-recipient text, photos and QR codes
  • PDF/X-1a export with CMYK, embedded fonts and flattened transparency
  • Client, self-hosted, or cloud rendering

Lob (backend)

  • US address verification and standardization
  • Printing across its commercial printer network
  • Address block, postage and the Intelligent Mail barcode
  • USPS First Class or Marketing Mail
  • Tracking events and webhooks, plus a PDF proof of each postcard

Technical details

  • Sizes: 4x6, 6x9 and 6x11 postcards. Only 4x6 postcards go to international addresses, and those need a from address.
  • Files: PDF, PNG or JPEG for each side, sized to 4.25 × 6.25, 6.25 × 9.25 or 6.25 × 11.25 in at 300 DPI. Send each side as a file upload or as a URL Lob fetches. Lob also renders HTML and its own saved templates.
  • PDF: PDF/X-1a, CMYK, flattened transparency, fonts embedded, no printer marks, under 5 MB.
  • Ink-free zone: 3.2835 × 2.375 in on 4x6 cards and 4 × 2.375 in on 6x9 and 6x11, 0.275 in from the right edge and 0.25 in from the bottom edge of the file.
  • Auth: HTTP Basic, with your API key as the username and an empty password. Test keys start with test_ and live keys with live_.
  • Use type: every postcard needs use_type set to marketing or operational, unless your account sets a default.
  • Retries: an Idempotency-Key header stops a retried request from creating a second postcard.
  • Webhooks: events such as postcard.created, postcard.rendered_pdf, postcard.mailed and postcard.delivered. Some fire only in live mode.
  • Rendering modes: client-side for the editor; server-side or the Cloud Render API for batch PDF export.

What you can build

Any Lob postcard flow where the design comes from your users:

  • Triggered postcards from CRM events: a welcome card, a win-back offer, a renewal reminder
  • Real estate "just listed" and "just sold" cards, with the listing photo and agent details per card
  • Nonprofit appeals with a personal greeting and ask amounts for each donor
  • Local service promotions with a QR code per household
  • Letters on the same canvas: Lob takes letter PDFs at 8.5 × 11 in, up to 60 pages single-sided for US addresses

FAQ

Do I need a Lob account?

Yes. You create the account at Lob and find your test and live API keys in the dashboard under Settings. Lob asks for a payment method before you make live requests. For pricing, see Lob's pricing page.

Can I test without mailing anything?

Yes. Requests with a test_ key go to Lob's test environment, which validates every request, charges no fees, and never prints or mails. Switch to the live_ key when you launch.

Why export PDF/X-1a instead of a regular PDF?

Lob's PDF preflight checklist requires PDF/X-1a. Lob runs an automated check that applies fixes on its own, and Lob warns that those fixes can change how the mail piece looks. Sending PDF/X-1a with CMYK color and embedded fonts from Polotno keeps the printed card close to the design.

Lob has merge variables. Why fill the template in Polotno?

Lob's merge variables fill HTML templates and QR code URLs. When the design comes from the Polotno editor, resolveVariables fills it before export, so each PDF Lob receives is the finished card for one recipient. The same filled design can also render as a PNG preview or an email.

Can users see where the address block goes?

Yes, if your editor draws it. The direct mail donor postcards demo shows the address-side zones on the canvas, locks the address block into its zone, and warns as soon as another element overlaps one. Your app can run the same check with design validation before it calls Lob.

Start building

Get a Polotno API key (a trial key from your Polotno dashboard works), size the canvas to Lob's file, and send the exported files to Lob from your backend with a test key first.

Related reading

Skip the build, cut dev costs, launch faster

TRUSTED BY

100,000+

CREATORS

300+

BUSINESSES

ExpediaUnbounceLovePopPostGridPredis.ai