feat: business card generator engine
All checks were successful
Build & Deploy / 🔍 Prepare (push) Successful in 9s
Build & Deploy / 🧪 QA (push) Successful in 53s
Build & Deploy / 🏗️ Build (push) Successful in 2m12s
Build & Deploy / 🚀 Deploy (push) Successful in 14s
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s

Adds react-pdf business card components and a ghostscript CMYK converter script
This commit is contained in:
2026-06-09 11:15:52 +02:00
parent 9c7ebe2567
commit 46a940f234
3 changed files with 257 additions and 0 deletions

View File

@@ -0,0 +1,101 @@
#!/usr/bin/env ts-node
/**
* Generate PDF Business Cards and convert to CMYK
*/
import * as fs from 'fs';
import * as path from 'path';
import * as React from 'react';
import { renderToBuffer } from '@react-pdf/renderer';
import { execSync } from 'child_process';
import { PDFBusinessCard, PersonData } from '../lib/pdf-business-card';
const CONFIG = {
outputDir: path.join(process.cwd(), 'public/downloads/business-cards'),
};
const PEOPLE: PersonData[] = [
{
name: 'Michael Bodemer',
position: 'Owner & Managing Director',
phone: '+49 151 462 467 98',
email: 'michael.bodemer@klz-cables.com',
website: 'www.klz-cables.com',
},
{
name: 'Klaus Mintel',
position: 'Managing Director',
phone: '+49 151 1775 2873',
email: 'klaus.mintel@klz-cables.com',
website: 'www.klz-cables.com',
},
];
async function ensureOutputDir() {
if (!fs.existsSync(CONFIG.outputDir)) {
fs.mkdirSync(CONFIG.outputDir, { recursive: true });
}
}
/**
* Konvertiert ein RGB PDF zu CMYK via Ghostscript.
*/
function convertToCMYK(inputPath: string, outputPath: string) {
console.log(`- Converting to CMYK via Ghostscript...`);
try {
// Basic CMYK conversion via Ghostscript.
// -dSAFER -dBATCH -dNOPAUSE
// -sDEVICE=pdfwrite
// -sColorConversionStrategy=CMYK
// -dProcessColorModel=/DeviceCMYK
const gsCommand = `gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -sOutputFile="${outputPath}" "${inputPath}"`;
execSync(gsCommand, { stdio: 'pipe' });
console.log(`✓ CMYK Print File generated: ${path.basename(outputPath)}`);
} catch (err: any) {
console.error(`❌ Ghostscript CMYK conversion failed! Is ghostscript (gs) installed?`);
console.error(err.message);
}
}
async function generateBusinessCards() {
await ensureOutputDir();
for (const person of PEOPLE) {
console.log(`\nGenerating Business Card for: ${person.name}`);
const safeName = person.name.replace(/\s+/g, '_');
const rgbFileName = `KLZ_BusinessCard_${safeName}_RGB.pdf`;
const cmykFileName = `KLZ_BusinessCard_${safeName}_CMYK_Print.pdf`;
const rgbPath = path.join(CONFIG.outputDir, rgbFileName);
const cmykPath = path.join(CONFIG.outputDir, cmykFileName);
console.log(`- Rendering React-PDF layout...`);
const buffer = await renderToBuffer(
React.createElement(PDFBusinessCard, {
person,
}),
);
fs.writeFileSync(rgbPath, buffer);
console.log(`✓ RGB Master generated: ${rgbFileName}`);
convertToCMYK(rgbPath, cmykPath);
}
}
async function main() {
console.log('--- KLZ Business Card Generator ---');
const start = Date.now();
try {
await generateBusinessCards();
console.log(`\n✅ Finished in ${((Date.now() - start) / 1000).toFixed(2)}s`);
} catch (error) {
console.error('\\n❌ Fatal error:', error);
process.exit(1);
}
}
main().catch(console.error);