This commit adds full quote PDF generation functionality with per-company letterhead branding: - Server-side PDF rendering using @react-pdf/renderer matching the sample quote layout - In-app modal PDF viewer with print, download, and new-tab controls - Letterhead service to fetch and apply company-specific branding (CNL/ISHERWOOD) - ZAR currency and date formatting utilities for South African quotes - Updated QuoteAttachment type to handle PocketBase's array-based file tokens - Fixed PocketBase attachment URL generation in quote email card - Removed deprecated `included_in_quote` field from QuoteItem and quotes service - Updated quote item creation test to validate draft item logic - Added comprehensive unit tests for PDF rendering and formatting helpers - Added dev scripts for debugging PDF and image rendering issues - Added sample generated PDF files for visual verification - Updated tsconfig to exclude development scripts directory - Added @react-pdf/renderer production dependency - Removed JEI as a valid letterhead option per requirements
38 lines
No EOL
1.2 KiB
TypeScript
38 lines
No EOL
1.2 KiB
TypeScript
/* eslint-disable */
|
|
import * as React from "react";
|
|
import { Document, Page, Image, pdf } from "@react-pdf/renderer";
|
|
import fs from "fs";
|
|
|
|
async function main() {
|
|
const png = fs.readFileSync("/tmp/debug-logo.png");
|
|
|
|
// Test all 4 src variants
|
|
const variants: Array<[string, any]> = [
|
|
["Blob (image/png)", new Blob([new Uint8Array(png)], { type: "image/png" })],
|
|
["Uint8Array", new Uint8Array(png)],
|
|
["Buffer (Node)", png],
|
|
["base64 string (NO data: prefix)", png.toString("base64")],
|
|
];
|
|
|
|
for (const [label, src] of variants) {
|
|
try {
|
|
const inst = pdf(
|
|
<Document><Page size="A4" style={{padding: 40}}>
|
|
<Image src={src} style={{ width: 110, height: 68 }} />
|
|
</Page></Document>
|
|
);
|
|
const out = Buffer.from(await inst.toString(), "binary");
|
|
console.log(`[${label}] size: ${out.length}`);
|
|
|
|
// Find image stream
|
|
const streamIdx = out.indexOf(Buffer.from("stream\n"));
|
|
if (streamIdx >= 0) {
|
|
const head = out.subarray(streamIdx + 7, streamIdx + 30);
|
|
console.log(` stream head: ${head.toString("hex")}`);
|
|
}
|
|
} catch (e) {
|
|
console.log(`[${label}] FAILED: ${e.message}`);
|
|
}
|
|
}
|
|
}
|
|
main().catch(e => { console.error("FAIL:", e); process.exit(1); }); |