38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
|
|
/* eslint-disable */
|
||
|
|
import * as React from "react";
|
||
|
|
import { Document, Page, Image, ImageBackground, View, pdf } from "@react-pdf/renderer";
|
||
|
|
import fs from "fs";
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
const buf = fs.readFileSync("/tmp/debug-logo.png");
|
||
|
|
|
||
|
|
console.log("=== Test 1: Image (default) ===");
|
||
|
|
const inst1 = pdf(
|
||
|
|
<Document><Page size="A4" style={{padding: 40}}>
|
||
|
|
<Image src={buf} style={{ width: 110, height: 68 }} debug />
|
||
|
|
</Page></Document>
|
||
|
|
);
|
||
|
|
const out1 = Buffer.from(await inst1.toString(), "binary");
|
||
|
|
console.log(" size:", out1.length);
|
||
|
|
|
||
|
|
console.log("=== Test 2: ImageBackground (no debug) ===");
|
||
|
|
const inst2 = pdf(
|
||
|
|
<Document><Page size="A4" style={{padding: 40}}>
|
||
|
|
<ImageBackground src={buf} style={{ width: 110, height: 68 }} />
|
||
|
|
</Page></Document>
|
||
|
|
);
|
||
|
|
const out2 = Buffer.from(await inst2.toString(), "binary");
|
||
|
|
console.log(" size:", out2.length);
|
||
|
|
|
||
|
|
console.log("=== Test 3: SVG with embedded JPEG base64 ===");
|
||
|
|
const b64 = buf.toString("base64");
|
||
|
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="110" height="68" viewBox="0 0 323 200"><image href="data:image/png;base64,${b64}" width="323" height="200"/></svg>`;
|
||
|
|
const inst3 = pdf(
|
||
|
|
<Document><Page size="A4" style={{padding: 40}}>
|
||
|
|
<Image src={svg} style={{ width: 110, height: 68 }} />
|
||
|
|
</Page></Document>
|
||
|
|
);
|
||
|
|
const out3 = Buffer.from(await inst3.toString(), "binary");
|
||
|
|
console.log(" size:", out3.length);
|
||
|
|
}
|
||
|
|
main().catch(e => { console.error("FAIL:", e); process.exit(1); });
|