feat(pdf): finalize business card generation with print standards and white variants
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Failing after 1m26s
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 1s
Nightly QA / 💨 Smoke & Health (push) Failing after 3m33s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Failing after 1m26s
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 1s
Nightly QA / 💨 Smoke & Health (push) Failing after 3m33s
- Replaced buggy RGB PDF backgrounds with exact Ghostscript outlining - Generated front/back dual pages natively in React-PDF - Applied high-end minimalist design standards to QR codes (no frames) - Established Ghostscript pipeline for reliable font-to-path generation - Added White variant generation process
This commit is contained in:
@@ -13,10 +13,12 @@ import QRCode from 'qrcode';
|
||||
|
||||
const CONFIG = {
|
||||
outputDir: path.join(process.cwd(), 'public/downloads/business-cards'),
|
||||
logoWhite: path.join(process.cwd(), 'public/logo-white.svg'),
|
||||
logoBlue: path.join(process.cwd(), 'public/logo-blue.svg'),
|
||||
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[] = [
|
||||
@@ -32,21 +34,14 @@ const PEOPLE: PersonData[] = [
|
||||
phone: '+49 151 1775 2873',
|
||||
email: 'klaus.mintel@klz-cables.com',
|
||||
},
|
||||
{
|
||||
name: 'Johannes Gleich',
|
||||
role: 'Platzhalter Rolle',
|
||||
phone: '+49 000 0000000',
|
||||
email: 'johannes.gleich@klz-cables.com',
|
||||
},
|
||||
];
|
||||
|
||||
function convertToCMYK(inputPath: string, outputPath: string) {
|
||||
console.log(`- Converting to CMYK via Ghostscript...`);
|
||||
try {
|
||||
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() {
|
||||
if (!fs.existsSync(CONFIG.outputDir)) {
|
||||
fs.mkdirSync(CONFIG.outputDir, { recursive: true });
|
||||
@@ -77,10 +72,10 @@ END:VCARD`;
|
||||
|
||||
const safeName = person.name.replace(/\s+/g, '_');
|
||||
const finalFileName = `KLZ_Visitenkarte_${safeName}.pdf`;
|
||||
const tempRgbPath = path.join(CONFIG.outputDir, `temp_rgb_${safeName}.pdf`);
|
||||
const rgbPath = path.join(CONFIG.outputDir, `RGB_${finalFileName}`);
|
||||
const finalPath = path.join(CONFIG.outputDir, finalFileName);
|
||||
|
||||
console.log(`- Rendering React-PDF layout...`);
|
||||
console.log(`- Rendering React-PDF layout (RGB ONLY)...`);
|
||||
const buffer = await renderToBuffer(
|
||||
React.createElement(PDFBusinessCard, {
|
||||
person,
|
||||
@@ -88,15 +83,36 @@ END:VCARD`;
|
||||
}),
|
||||
);
|
||||
|
||||
fs.writeFileSync(tempRgbPath, buffer);
|
||||
convertToCMYK(tempRgbPath, finalPath);
|
||||
fs.writeFileSync(rgbPath, buffer);
|
||||
|
||||
// Clean up temporary RGB file
|
||||
if (fs.existsSync(tempRgbPath)) {
|
||||
fs.unlinkSync(tempRgbPath);
|
||||
}
|
||||
console.log(`- Outlining fonts via Ghostscript (Keeping RGB)...`);
|
||||
const gsCommand = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalPath}" "${rgbPath}"`;
|
||||
execSync(gsCommand, { stdio: 'ignore' });
|
||||
|
||||
console.log(`✓ Final Print File generated: ${finalFileName}`);
|
||||
fs.unlinkSync(rgbPath);
|
||||
|
||||
console.log(`✓ Final Print File generated (Fonts to Paths, RGB preserved): ${finalFileName}`);
|
||||
|
||||
// Generate White Variant
|
||||
const finalFileNameWhite = `KLZ_Visitenkarte_${safeName}_White.pdf`;
|
||||
const rgbPathWhite = path.join(CONFIG.outputDir, `RGB_${finalFileNameWhite}`);
|
||||
const finalPathWhite = path.join(CONFIG.outputDir, finalFileNameWhite);
|
||||
|
||||
console.log(`- Rendering White Variant...`);
|
||||
const bufferWhite = await renderToBuffer(
|
||||
React.createElement(PDFBusinessCard, {
|
||||
person,
|
||||
qrCodeDataUrl,
|
||||
isWhiteVariant: true,
|
||||
}),
|
||||
);
|
||||
|
||||
fs.writeFileSync(rgbPathWhite, bufferWhite);
|
||||
|
||||
const gsCommandWhite = `gs -dNoOutputFonts -sDEVICE=pdfwrite -o "${finalPathWhite}" "${rgbPathWhite}"`;
|
||||
execSync(gsCommandWhite, { stdio: 'ignore' });
|
||||
fs.unlinkSync(rgbPathWhite);
|
||||
console.log(`✓ White Variant generated: ${finalFileNameWhite}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user