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

32 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import * as React from "react";
import { Document, Page, Image, pdf, Font } from "@react-pdf/renderer";
import fs from "fs";
async function main() {
const buf = fs.readFileSync("/tmp/debug-logo.png");
// Maybe the bug is in the PDF output not the data. Let me check
// by writing the data BEFORE the PDF operations.
console.log("=== Reading PNG ===");
console.log("PNG signature:", buf.slice(0, 8).toString("hex"));
// Create a doc with NO image, just the text "HELLO"
const inst = pdf(
<Document>
<Page size="A4" style={{padding: 40}}>
<Image src={buf} style={{width: 110, height: 68}} cache={false} />
</Page>
</Document>
);
const out = Buffer.from(await inst.toString(), "binary");
console.log("PDF size:", out.length);
// Look for the image data in the PDF
const idx = out.indexOf(Buffer.from([0x89, 0x50, 0x4e, 0x47]));
console.log("PNG signature found in PDF at:", idx);
if (idx >= 0) {
console.log("Uncompressed PNG bytes!");
}
}
main().catch(e => { console.error("FAIL:", e); process.exit(1); });