The approach
Generating an eviction notice programmatically comes down to two pieces: one HTML template with placeholders, and a small function that swaps in tenant, property, and jurisdiction details before rendering to PDF. Because requirements (notice period, required language, service method) differ by state, keep those values in a per-state config object instead of hard-coding them into the template.
Generate the PDF
import Anvil from '@anvilco/anvil'
const anvilClient = new Anvil({ apiKey: process.env.ANVIL_API_KEY })
// Populate with the requirements for each state you operate in.
// Confirm the current notice period and language against the
// governing state statute before sending any notice.
const STATE_RULES = {
TX: { noticeType: 'Notice to Vacate', noticePeriodDays: 3 },
// add the states you operate in...
}
function buildNoticeHtml({ tenantName, propertyAddress, reason, state }) {
const rule = STATE_RULES[state]
return `
<h1>${rule.noticeType}</h1>
<p>To: ${tenantName}</p>
<p>Property: ${propertyAddress}</p>
<p>You are hereby notified to vacate the premises within
${rule.noticePeriodDays} days for the following reason:
${reason}.</p>
`
}
async function generateNotice(tenant) {
const payload = {
title: `Eviction Notice - ${tenant.tenantName}`,
type: 'html',
data: {
html: buildNoticeHtml(tenant),
css: 'body { font-family: sans-serif; font-size: 14px; }',
},
}
const { statusCode, data } = await anvilClient.generatePDF(payload)
if (statusCode !== 200) throw new Error('PDF generation failed')
return data // PDF binary; write to disk with no encoding
}Why this shape scales
The template stays constant while the config object carries everything that varies. To bulk-generate, map over your tenant list and call generateNotice for each. Anvil's PDF generation endpoint accepts HTML and full CSS, so one template renders variable-length documents. Write the returned bytes to disk with no encoding, or the file will be corrupt.
Caveats
Notice periods, required disclosures, and service rules are legal requirements that change by state and over time, so treat STATE_RULES as something a qualified person reviews, not a fixed source of truth. On billing, each generated PDF counts as one PDF generation; development-key requests are free but watermarked, which is handy while you build and test the template.
Back to All Questions