WFDASH-WEBAPP/scripts/dev/debug-png.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

32 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");
console.log("PNG bytes:", png.length, "first 8:", png.subarray(0, 8).toString("hex"));
const inst = pdf(
<Document><Page size="A4" style={{padding: 40}}>
<Image src={png} style={{ width: 110, height: 68 }} />
</Page></Document>
);
const out = Buffer.from(await inst.toString(), "binary");
fs.writeFileSync("/tmp/test-png.pdf", out);
console.log("PDF size:", out.length);
// Find image stream
const dctIdx = out.indexOf("/FlateDecode");
if (dctIdx >= 0) {
const streamStart = out.indexOf(Buffer.from("stream\n"), dctIdx);
if (streamStart >= 0) {
const head = out.subarray(streamStart + 7, streamStart + 30);
console.log("PNG stream head:", head.toString("hex"));
console.log("PNG SOI valid?", head[0] === 0x89 && head[1] === 0x50 && head[2] === 0x4e && head[3] === 0x47);
}
} else {
console.log("No FlateDecode (PNG) stream found");
}
}
main().catch(e => { console.error("FAIL:", e); process.exit(1); });