WFDASH-WEBAPP/scripts/dev/test-render.tsx
SJCoetz 714e910949 feat: add branded quote PDF generation and in-app viewer
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
2026-06-23 08:30:38 +02:00

30 lines
1,004 B
TypeScript

import * as React from "react";
import { Document, Page, View, Image, pdf } from "@react-pdf/renderer";
import fs from "fs";
async function main() {
// Read a real JPEG
const buf = fs.readFileSync("/tmp/debug-logo.bin");
console.log("Input bytes:", buf.length);
console.log("First bytes:", buf.slice(0, 4).toString("hex"));
// Try to use it directly as Image src
const inst = pdf(
<Document>
<Page size="A4" style={{ padding: 40 }}>
<Image src={buf} style={{ width: 110, height: 68 }} />
</Page>
</Document>
);
const out = Buffer.from(await inst.toString(), "binary");
fs.writeFileSync("/tmp/raw-buf-test.pdf", out);
console.log("PDF size:", out.length);
// Check the image bytes
const idx = out.find(Buffer.from("stream\n"));
if (idx >= 0) {
console.log("Stream at:", idx);
console.log("First 20 bytes after stream:", out.subarray(idx+7, idx+27).toString("hex"));
}
}
main().catch(e => { console.error("FAIL:", e); process.exit(1); });