/* eslint-disable */
import * as React from "react";
import { Document, Page, Image, pdf } from "@react-pdf/renderer";
import fs from "fs";
async function main() {
// Read a real JPEG from disk
const buf = fs.readFileSync("/tmp/debug-logo.bin");
console.log("Input bytes:", buf.length, "first 4:", buf.slice(0, 4).toString("hex"));
// Test 1: direct Buffer
console.log("\n=== Test 1: Buffer src ===");
const inst1 = pdf(
);
const out1 = Buffer.from(await inst1.toString(), "binary");
console.log(" size:", out1.length, "first bytes:", out1.subarray(0, 8).toString("hex"));
checkImage(out1, "buf");
// Test 2: data URI
console.log("\n=== Test 2: data URI src ===");
const dataUri = `data:image/jpeg;base64,${buf.toString("base64")}`;
const inst2 = pdf(
);
const out2 = Buffer.from(await inst2.toString(), "binary");
console.log(" size:", out2.length);
checkImage(out2, "datauri");
// Test 3: URL
console.log("\n=== Test 3: URL src ===");
const url = "https://pocketbase-gnqc88suy8fqk6wyryjjdpvl.169.239.180.130.sslip.io/api/files/pbc_1010367695/851t7163ks1f9qk/1u8lvckq51g_my2g8gttaf.jpg";
const inst3 = pdf(
);
const out3 = Buffer.from(await inst3.toString(), "binary");
console.log(" size:", out3.length);
checkImage(out3, "url");
}
function checkImage(pdfBuf: Buffer, label: string) {
// Find the JPEG stream inside the PDF
const dctIdx = pdfBuf.indexOf("/DCTDecode");
if (dctIdx < 0) {
console.log(` [${label}] no DCTDecode (JPEG) stream found`);
return;
}
// Find the stream that follows
const streamStart = pdfBuf.indexOf(Buffer.from("stream\n"), dctIdx);
if (streamStart < 0) {
console.log(` [${label}] no stream after DCTDecode`);
return;
}
const head = pdfBuf.subarray(streamStart + 7, streamStart + 20);
console.log(` [${label}] JPEG stream head: ${head.toString("hex")}`);
console.log(` [${label}] first 2 bytes valid JPEG SOI? ${head[0] === 0xff && head[1] === 0xd8}`);
}
main().catch((err) => { console.error("FAIL:", err); process.exit(1); });