This commit is contained in:
31
docs/snippets/wasm/config/image-config.ts
Normal file
31
docs/snippets/wasm/config/image-config.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { ExtractionConfig } from "@kreuzberg/wasm";
|
||||
import { extractBytes, initWasm } from "@kreuzberg/wasm";
|
||||
|
||||
async function extractImagesWithConfig() {
|
||||
await initWasm();
|
||||
|
||||
const bytes = new Uint8Array(await fetch("document.pdf").then((r) => r.arrayBuffer()));
|
||||
|
||||
const config: ExtractionConfig = {
|
||||
images: {
|
||||
extractImages: true,
|
||||
targetDpi: 300,
|
||||
maxDimension: 2048,
|
||||
preserveAspectRatio: true,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await extractBytes(bytes, "application/pdf", config);
|
||||
|
||||
if (result.images) {
|
||||
console.log(`Extracted ${result.images.length} images`);
|
||||
|
||||
result.images.forEach((image) => {
|
||||
console.log(
|
||||
`Image: ${image.width}x${image.height}, Format: ${image.format}, DPI: ${image.description}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
extractImagesWithConfig().catch(console.error);
|
||||
Reference in New Issue
Block a user