Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 11s
Build & Deploy / 🧪 QA (push) Failing after 1m24s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
128 lines
4.0 KiB
TypeScript
128 lines
4.0 KiB
TypeScript
#!/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';
|
|
import QRCode from 'qrcode';
|
|
|
|
const CONFIG = {
|
|
outputDir: path.join(process.cwd(), 'public/downloads/business-cards'),
|
|
logoWhite: path.join(process.cwd(), 'public/logo-white.png'),
|
|
logoBlue: path.join(process.cwd(), 'public/logo-blue.png'),
|
|
logoFull: path.join(process.cwd(), 'public/logo-full.png'),
|
|
truckImage: path.join(process.cwd(), 'public/truck.png'),
|
|
fontRegular: path.join(process.cwd(), 'public/fonts/Inter-Regular.ttf'),
|
|
fontBold: path.join(process.cwd(), 'public/fonts/Inter-Bold.ttf'),
|
|
};
|
|
|
|
const PEOPLE: PersonData[] = [
|
|
{
|
|
name: 'Michael Bodemer',
|
|
role: 'Managing Director',
|
|
phone: '+49 151 462 467 98',
|
|
email: 'michael.bodemer@klz-cables.com',
|
|
},
|
|
{
|
|
name: 'Klaus Mintel',
|
|
role: 'Managing Director',
|
|
phone: '+49 151 1775 2873',
|
|
email: 'Klaus.mintel@klz-cables.com',
|
|
},
|
|
{
|
|
name: 'Johannes Gleich',
|
|
role: 'Senior Key Account Manager',
|
|
phone: '+49 172 739 1109',
|
|
email: 'johannes.gleich@klz-cables.com',
|
|
},
|
|
];
|
|
|
|
async function generateBusinessCards() {
|
|
if (!fs.existsSync(CONFIG.outputDir)) {
|
|
fs.mkdirSync(CONFIG.outputDir, { recursive: true });
|
|
}
|
|
|
|
for (const person of PEOPLE) {
|
|
console.log(`\nGenerating Business Card for: ${person.name}`);
|
|
|
|
// Generate VCard QR Code
|
|
const lastName = person.name.split(' ').slice(1).join(' ');
|
|
const firstName = person.name.split(' ')[0];
|
|
const vcard = `BEGIN:VCARD
|
|
VERSION:3.0
|
|
N:${lastName};${firstName};;;
|
|
FN:${person.name}
|
|
ORG:KLZ Vertriebs GmbH
|
|
TITLE:${person.role}
|
|
TEL;TYPE=WORK,VOICE:${person.phone}
|
|
EMAIL;TYPE=PREF,INTERNET:${person.email}
|
|
URL:https://klz-cables.com
|
|
END:VCARD`;
|
|
|
|
const qrCodeDataUrl = await QRCode.toDataURL(vcard, {
|
|
width: 400,
|
|
margin: 0,
|
|
color: { dark: '#000000', light: '#ffffff' },
|
|
});
|
|
|
|
const safeName = person.name.replace(/\s+/g, '_');
|
|
const finalFileName = `KLZ_Visitenkarte_${safeName}.pdf`;
|
|
const rgbPath = path.join(CONFIG.outputDir, `RGB_${finalFileName}`);
|
|
const finalPath = path.join(CONFIG.outputDir, finalFileName);
|
|
|
|
console.log(`- Rendering React-PDF layout (RGB ONLY, Blue Variant)...`);
|
|
const buffer = await renderToBuffer(
|
|
React.createElement(PDFBusinessCard, {
|
|
person,
|
|
qrCodeDataUrl,
|
|
variant: 'blue', // Explicitly use blue now
|
|
}),
|
|
);
|
|
|
|
fs.writeFileSync(rgbPath, buffer);
|
|
|
|
console.log(`- Outlining fonts via Ghostscript (Keeping RGB)...`);
|
|
const gsCommand = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalPath}" "${rgbPath}"`;
|
|
execSync(gsCommand, { stdio: 'ignore' });
|
|
|
|
fs.unlinkSync(rgbPath);
|
|
|
|
console.log(`✓ Final Print File generated (Fonts to Paths, RGB preserved): ${finalFileName}`);
|
|
|
|
// Convert to CMYK for Viaprinto
|
|
const finalFileNameCMYK = `KLZ_Visitenkarte_${safeName}_Viaprinto_CMYK.pdf`;
|
|
const finalPathCMYK = path.join(CONFIG.outputDir, finalFileNameCMYK);
|
|
|
|
console.log(`- Converting to CMYK for Viaprinto...`);
|
|
const cmykScript =
|
|
'/Users/marcmintel/.gemini/config/plugins/mintel-ui-standards-plugin/skills/mintel-print-workflow/scripts/convert-cmyk.sh';
|
|
const cmykCommand = `bash "${cmykScript}" "${finalPath}" "${finalPathCMYK}"`;
|
|
try {
|
|
execSync(cmykCommand, { stdio: 'ignore' });
|
|
console.log(`✓ CMYK Print File generated: ${finalFileNameCMYK}`);
|
|
} catch (e) {
|
|
console.error(`❌ CMYK conversion failed! Is Ghostscript installed?`);
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|