32 lines
1.2 KiB
TypeScript
32 lines
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); });
|