WFDASH-WEBAPP/scripts/dev/debug-image-test.tsx

55 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

import * as React from "react";
import { renderQuotePdf } from "@/lib/pdf/render";
import { Document, Page, View, Image } from "@react-pdf/renderer";
import type { Quote, QuoteItem, Customer, Letterhead } from "@/lib/types";
import fs from "fs";
async function main() {
const buf = fs.readFileSync("/tmp/debug-logo.bin");
const dataUri = `data:image/jpeg;base64,${buf.toString("base64")}`;
const lh = {
id: "lh1", collectionId: "pbc_1010367695", collectionName: "letterhead_settings",
created: new Date().toISOString(), updated: new Date().toISOString(),
display_name: "CNL",
address: "x", phone: "", email: "", vat_number: "",
registration_number: "", bank_name: "", bank_account_number: "",
bank_branch_code: "", terms: "",
default_markup_percent: 0, footer_text: "", logo: "",
is_active: true, company: "CNL", accent_color: "#738224",
} as Letterhead;
// Minimal test doc with just the image in different configs
const pdfBuf = await new Promise<Buffer>(async (resolve, reject) => {
try {
const inst = (await import("@react-pdf/renderer")).pdf(
<Document>
<Page size="A4" style={{ padding: 40, fontFamily: "Helvetica" }}>
{/* Test 1: data URI src with style only */}
<View style={{ marginBottom: 20 }}>
<Image src={dataUri} style={{ width: 110, height: 110 }} />
</View>
{/* Test 2: data URI src with explicit width/height props */}
<View style={{ marginBottom: 20 }}>
<Image src={dataUri} width={110} height={110} />
</View>
{/* Test 3: raw buffer src */}
<View style={{ marginBottom: 20 }}>
<Image src={buf as any} style={{ width: 110, height: 110 }} />
</View>
{/* Test 4: very large so we can definitely see it */}
<Image src={dataUri} style={{ width: 200, height: 200 }} />
</Page>
</Document>
);
const s = await inst.toString();
resolve(Buffer.from(s, "binary"));
} catch (e) {
reject(e);
}
});
fs.writeFileSync("/tmp/debug-image-test.pdf", pdfBuf);
console.log("PDF size:", pdfBuf.length);
}
main().catch((e) => { console.error("FAIL", e); process.exit(1); });