#!/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'), ghostscriptScript: '/Users/marcmintel/.gemini/config/plugins/mintel-ui-standards-plugin/skills/mintel-print-workflow/scripts/convert-cmyk.sh', }; const PEOPLE: PersonData[] = [ { name: 'Michael Bodemer', role: 'Owner & 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}`); const lastName = person.name.split(' ').slice(1).join(' '); const firstName = person.name.split(' ')[0]; // To make the QR code extremely coarse (minimalist), we cannot encode all contact details into it directly. // Instead, we create a physical .vcf file and encode ONLY its URL into the QR Code (e.g. 35 chars vs 140 chars). const shortId = person.name.toLowerCase().replace(/[^a-z0-9]/g, ''); // "michaelbodemer" const vcfUrl = `https://klz-cables.com/v/${shortId}.vcf`; const vcardFull = `BEGIN:VCARD\r\nVERSION:3.0\r\nN:${lastName};${firstName};;;\r\nFN:${person.name}\r\nORG:KLZ Vertriebs GmbH\r\nTITLE:${person.role}\r\nTEL;TYPE=WORK,VOICE:${person.phone}\r\nEMAIL;TYPE=PREF,INTERNET:${person.email}\r\nURL:https://klz-cables.com\r\nEND:VCARD`; // Save the physical .vcf file so it can be served by Next.js from /public/v/ const vcardDir = path.join(process.cwd(), 'public/v'); if (!fs.existsSync(vcardDir)) fs.mkdirSync(vcardDir, { recursive: true }); fs.writeFileSync(path.join(vcardDir, `${shortId}.vcf`), vcardFull); const qrCodeDataUrl = await QRCode.toDataURL(vcfUrl, { width: 400, margin: 0, errorCorrectionLevel: 'L', // Low error correction = less dots color: { dark: '#000000', light: '#ffffff' }, }); const safeName = person.name.replace(/\s+/g, '_'); // 1. STANDARD DIGITAL PDF (RGB, no letterpress mask) console.log(`- Rendering standard digital PDF (RGB ONLY, Blue Variant)...`); const finalFileName = `KLZ_Visitenkarte_${safeName}.pdf`; const tempFileName = `temp_${finalFileName}`; const finalPath = path.join(CONFIG.outputDir, finalFileName); const tempPath = path.join(CONFIG.outputDir, tempFileName); let buffer = await renderToBuffer( React.createElement(PDFBusinessCard, { person, qrCodeDataUrl, variant: 'blue', isViaprinto: false, }), ); fs.writeFileSync(tempPath, buffer); // Convert fonts to outlines via ghostscript const gsCommand = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalPath}" "${tempPath}"`; execSync(gsCommand, { stdio: 'inherit' }); // fs.unlinkSync(tempPath); console.log(`✓ Final Print File generated (Fonts to Paths, RGB preserved): ${finalFileName}`); // 2. VIAPRINTO PDF (Letterpress mask, CMYK) console.log(`- Rendering Viaprinto PDF (Letterpress mask)...`); const tempViaprintoPath = path.join(CONFIG.outputDir, `temp_viaprinto_${safeName}.pdf`); buffer = await renderToBuffer( React.createElement(PDFBusinessCard, { person, qrCodeDataUrl, variant: 'blue', isViaprinto: true, }), ); fs.writeFileSync(tempViaprintoPath, buffer); // Convert to CMYK for Viaprinto const finalFileNameCMYK = `KLZ_Visitenkarte_${safeName}_Viaprinto_CMYK_91x61mm_3mmBleed.pdf`; const finalPathCMYK = path.join(CONFIG.outputDir, finalFileNameCMYK); console.log(`- Converting to CMYK for Viaprinto...`); const cmykCommand = `bash "${CONFIG.ghostscriptScript}" "${tempViaprintoPath}" "${finalPathCMYK}"`; try { execSync(cmykCommand, { stdio: 'inherit' }); fs.unlinkSync(tempViaprintoPath); console.log(`✓ CMYK Print File generated: ${finalFileNameCMYK}`); } catch (e) { console.error(`❌ CMYK conversion failed! Is Ghostscript installed?`); } // 3. NO TRUCK PDF (RGB) console.log(`- Rendering No Truck Variant (RGB)...`); const noTruckFileName = `KLZ_Visitenkarte_${safeName}_NoTruck.pdf`; const tempNoTruckPath = path.join(CONFIG.outputDir, `temp_${noTruckFileName}`); const finalNoTruckPath = path.join(CONFIG.outputDir, noTruckFileName); buffer = await renderToBuffer( React.createElement(PDFBusinessCard, { person, qrCodeDataUrl, variant: 'blue', isViaprinto: false, withTruck: false, }), ); fs.writeFileSync(tempNoTruckPath, buffer); const gsNoTruckCommand = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalNoTruckPath}" "${tempNoTruckPath}"`; execSync(gsNoTruckCommand, { stdio: 'inherit' }); fs.unlinkSync(tempNoTruckPath); // 4. CROP MARKS PDF (RGB) console.log(`- Rendering Crop Marks Variant (RGB)...`); const cropMarksFileName = `KLZ_Visitenkarte_${safeName}_CropMarks.pdf`; const tempCropMarksPath = path.join(CONFIG.outputDir, `temp_${cropMarksFileName}`); const finalCropMarksPath = path.join(CONFIG.outputDir, cropMarksFileName); buffer = await renderToBuffer( React.createElement(PDFBusinessCard, { person, qrCodeDataUrl, variant: 'blue', isViaprinto: false, withCropMarks: true, }), ); fs.writeFileSync(tempCropMarksPath, buffer); const gsCropMarksCommand = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalCropMarksPath}" "${tempCropMarksPath}"`; execSync(gsCropMarksCommand, { stdio: 'inherit' }); fs.unlinkSync(tempCropMarksPath); console.log(`✓ Crop Marks Print File generated: ${cropMarksFileName}`); } } 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);