import { Document, Font, Image, Page, Text, View } from "@react-pdf/renderer"; import QRCodeUtil from "qrcode"; import type { Invoice } from "../../types"; import { EditorContent } from "./components/editor-content"; import { LineItems } from "./components/line-items"; import { Meta } from "./components/meta"; import { Note } from "./components/note"; import { PaidWatermark } from "./components/paid-watermark"; import { PaymentDetails } from "./components/payment-details"; import { QRCode } from "./components/qr-code"; import { Summary } from "./components/summary"; Font.register({ family: "Inter", fonts: [ { src: "https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfMZhrib2Bg-4.ttf", fontWeight: 400, }, { src: "https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuI6fMZhrib2Bg-4.ttf", fontWeight: 500, }, { src: "https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuGKYMZhrib2Bg-4.ttf", fontWeight: 600, }, { src: "https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuFuYMZhrib2Bg-4.ttf", fontWeight: 700, }, // Italic fonts { src: "https://fonts.gstatic.com/s/inter/v19/UcCM3FwrK3iLTcvneQg7Ca725JhhKnNqk4j1ebLhAm8SrXTc2dthjQ.ttf", fontWeight: 400, fontStyle: "italic", }, { src: "https://fonts.gstatic.com/s/inter/v19/UcCM3FwrK3iLTcvneQg7Ca725JhhKnNqk4j1ebLhAm8SrXTc69thjQ.ttf", fontWeight: 500, fontStyle: "italic", }, { src: "https://fonts.gstatic.com/s/inter/v19/UcCM3FwrK3iLTcvneQg7Ca725JhhKnNqk4j1ebLhAm8SrXTcB9xhjQ.ttf", fontWeight: 600, fontStyle: "italic", }, { src: "https://fonts.gstatic.com/s/inter/v19/UcCM3FwrK3iLTcvneQg7Ca725JhhKnNqk4j1ebLhAm8SrXTcPtxhjQ.ttf", fontWeight: 700, fontStyle: "italic", }, ], }); type PdfTemplateOptions = { isReceipt?: boolean; }; export async function PdfTemplate( { invoiceNumber, issueDate, dueDate, paidAt, template, lineItems, customerDetails, fromDetails, discount, paymentDetails, noteDetails, currency, vat, tax, amount, topBlock, bottomBlock, token, }: Invoice, options?: PdfTemplateOptions, ) { const isReceipt = options?.isReceipt ?? false; if (!template) { throw new Error("Invoice template is required to render PDF"); } // Override title for receipt const title = isReceipt ? "Receipt" : template.title; let qrCode = null; if (template.includeQr) { qrCode = await QRCodeUtil.toDataURL(`https://app.midday.ai/i/${token}`, { margin: 0, width: 40 * 3, }); } return ( {template?.logoUrl && ( )} {template.fromLabel} {template.customerLabel} {isReceipt && ( )} {qrCode && } ); }