Juno checks in January 10 and leaves January 13. The recorded rabies expiry is January 13, so it covers the visit under this facility's sample policy. The recorded bordetella expiry is January 11, so the run card flags it for review. Check the full stay before printing the card that goes on the kennel door.
Compare calendar dates through checkout
The example checks the vaccines configured by the facility. Each expiry is the last day the facility accepts the record, so an expiry equal to checkout passes. Store arrival, checkout, and expiry as property-local YYYY-MM-DD dates. Validate them before comparing strings. The UTC round-trip below detects impossible inputs such as February 29, 2027 without converting a booking date to a local timestamp.
Keep missing and malformed dates separate from dates that expire before arrival or during the stay. The same decision rows feed a JSON audit and the printable card. The card fixture includes the dog, run assignment, dates, and feeding instruction. Staff can act on the record status at a glance, and the front desk can review the exact date in the audit.
Fit two cards on US Letter paper
US Letter is 612 by 792 PDF points. Give each card 348 points of height inside 36-point margins with a 24-point gap. Measure each text line with the embedded font before drawing. This sample rejects overflow so long input cannot disappear off a card. The fixtures use characters covered by standard Helvetica. For multilingual data, embed a font that covers the input and wrap text within the card's bounds. pdf-lib PDFDocument API · Font measurements
Save the block as kennel.mts. In the same directory, run npm install pdf-lib@1.17.1 and then node kennel.mts using Node.js 24. Three bookings produce a two-page kennel-run-cards.pdf and vaccine-audit.json. Node.js TypeScript documentation
import assert from "node:assert/strict"; import { writeFile } from "node:fs/promises"; import { PDFDocument, StandardFonts, rgb, type PDFFont, type PDFPage } from "pdf-lib"; const required = ["Rabies", "Bordetella", "Distemper"] as const; type Vaccine = typeof required[number]; type Booking = { id: string; dog: string; run: string; arrival: string; checkout: string; feed: string; records: Partial<Record<Vaccine, string>>; }; function dateKey(value: string | undefined): string | null { if (value === undefined || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null; const instant = new Date(`${value}T00:00:00Z`); return Number.isFinite(instant.getTime()) && instant.toISOString().slice(0, 10) === value ? value : null; } function audit(booking: Booking) { const arrival = dateKey(booking.arrival); const checkout = dateKey(booking.checkout); assert(arrival && checkout && arrival <= checkout, `${booking.id}: invalid stay window`); return required.map((vaccine) => { const recordedExpiry = booking.records[vaccine]; const expiry = dateKey(recordedExpiry); let status = "Valid through checkout"; if (recordedExpiry === undefined) status = "Missing record"; else if (expiry === null) status = "Invalid date"; else if (expiry < arrival) status = "Expired at intake"; else if (expiry < checkout) status = "Expires during stay"; return { vaccine, recordedExpiry: recordedExpiry ?? null, status }; }); } const PAGE_WIDTH = 612; const PAGE_HEIGHT = 792; const MARGIN = 36; const GAP = 24; const CARD_HEIGHT = (PAGE_HEIGHT - 2 * MARGIN - GAP) / 2; const CARD_WIDTH = PAGE_WIDTH - 2 * MARGIN; function drawCard(page: PDFPage, font: PDFFont, booking: Booking, checks: ReturnType<typeof audit>, slot: number) { const top = PAGE_HEIGHT - MARGIN - slot * (CARD_HEIGHT + GAP); page.drawRectangle({ x: MARGIN, y: top - CARD_HEIGHT, width: CARD_WIDTH, height: CARD_HEIGHT, borderColor: rgb(0.2, 0.2, 0.2), borderWidth: 1 }); function text(value: string, offset: number, size = 12, x = MARGIN + 16) { const end = MARGIN + CARD_WIDTH - 16; assert(font.widthOfTextAtSize(value, size) <= end - x, `${booking.id}: card text exceeds available width`); page.drawText(value, { x, y: top - offset, size, font }); } text(`RUN ${booking.run} / ${booking.id}`, 34, 18); text(booking.dog, 72, 24); text(`${booking.arrival} to ${booking.checkout}`, 100); text(`Feeding: ${booking.feed}`, 134); text(checks.every((row) => row.status === "Valid through checkout") ? "RECORD DATES OK" : "RECORD DATES: REVIEW", 178, 14); checks.forEach((row, index) => { const offset = 206 + 24 * index; text(row.vaccine, offset); text(row.status, offset, 12, MARGIN + 158); }); text("Staff initials: _________________________", 308); } const stay = { arrival: "2027-01-10", checkout: "2027-01-13" }; const bookings: Booking[] = [ { ...stay, id: "B-101", dog: "Juno", run: "A2", feed: "Use labeled food bin", records: { Rabies: "2027-01-13", Bordetella: "2027-01-11" } }, { ...stay, id: "B-102", dog: "Atlas", run: "A3", feed: "Use labeled food bin", records: { Rabies: "2027-01-09", Bordetella: "2027-02-29", Distemper: "2027-05-01" } }, { ...stay, id: "B-103", dog: "Pepper", run: "B1", feed: "Use labeled food bin", records: { Rabies: "2027-01-13", Bordetella: "2027-09-21", Distemper: "2028-02-29" } }, ]; const auditRows = bookings.map((booking) => ({ bookingId: booking.id, checks: audit(booking) })); assert.deepEqual(auditRows.map(({ checks }) => checks.map(({ status }) => status)), [ ["Valid through checkout", "Expires during stay", "Missing record"], ["Expired at intake", "Invalid date", "Valid through checkout"], ["Valid through checkout", "Valid through checkout", "Valid through checkout"], ]); assert.throws(() => audit({ ...bookings[0], checkout: "2027-01-09" }), /invalid stay window/); const doc = await PDFDocument.create(); const font = await doc.embedFont(StandardFonts.Helvetica); for (let index = 0; index < bookings.length; index += 1) { const slot = index % 2; const page = slot === 0 ? doc.addPage([PAGE_WIDTH, PAGE_HEIGHT]) : doc.getPage(doc.getPageCount() - 1); drawCard(page, font, bookings[index], auditRows[index].checks, slot); } const bytes = await doc.save(); const reopened = await PDFDocument.load(bytes); assert.equal(reopened.getPageCount(), 2); assert.deepEqual(reopened.getPage(0).getSize(), { width: 612, height: 792 }); await writeFile("kennel-run-cards.pdf", bytes); await writeFile("vaccine-audit.json", JSON.stringify(auditRows, null, 2) + "\n"); console.log(`Wrote ${reopened.getPageCount()} PDF pages and ${auditRows.length} booking audits`); Print a proof at actual size to check the run labels and spacing. Use the same booking ID on the run card and the staff schedule so revised assignments can be traced to the right animal. For a boarding intake workflow with run card PDFs and a schedule workbook, see PetBoardPack.
