12 KiB
12 KiB
PDF Datasheet Generator - Final Implementation
✅ Task Complete: ALL Requirements Met
Requirements from User
- ✅ Include ALL Excel data - All 42+ columns extracted
- ✅ One table per voltage rating - 6/10, 12/20, 18/30 kV, etc.
- ✅ ALL 13 columns in EVERY table - Even if empty
- ✅ Specific headers: DI, RI, Wi, Ibl, Ibe, Ik, Wm, Rbv, Ø, Fzv, Al, Cu, G
- ✅ Full-width columns - Tables span page width
- ✅ Handle missing data - Empty columns shown
- ✅ Clean design - Professional industrial layout
Implementation Summary
Key Changes Made
1. Complete Excel Data Extraction (Lines 203-283)
const columnMapping = {
// 13 Required Headers
'DI': { header: 'DI', unit: 'mm', key: 'DI' },
'RI': { header: 'RI', unit: 'Ohm/km', key: 'RI' },
'Wi': { header: 'Wi', unit: 'mm', key: 'Wi' },
'Ibl': { header: 'Ibl', unit: 'A', key: 'Ibl' },
'Ibe': { header: 'Ibe', unit: 'A', key: 'Ibe' },
'Ik': { header: 'Ik', unit: 'kA', key: 'Ik' },
'Wm': { header: 'Wm', unit: 'mm', key: 'Wm' },
'Rbv': { header: 'Rbv', unit: 'mm', key: 'Rbv' },
'Ø': { header: 'Ø', unit: 'mm', key: 'Ø' },
'Fzv': { header: 'Fzv', unit: 'N', key: 'Fzv' },
'Al': { header: 'Al', unit: '', key: 'Al' },
'Cu': { header: 'Cu', unit: '', key: 'Cu' },
'G': { header: 'G', unit: 'kg/km', key: 'G' },
// 31 Additional Columns (for complete data)
'conductor diameter': { header: 'Conductor diameter', unit: 'mm', key: 'cond_diam' },
'capacitance': { header: 'Capacitance', unit: 'uF/km', key: 'cap' },
// ... 29 more
};
2. Smart Data Separation (Lines 327-447)
// Global constants (same for all voltages) → Technical Data
const globalConstantColumns = new Set<string>();
for (const { excelKey, mapping } of matchedColumns) {
const values = rows.map(r => normalizeValue(String(r?.[excelKey] ?? ''))).filter(Boolean);
const unique = Array.from(new Set(values.map(v => v.toLowerCase())));
if (unique.length === 1 && values.length > 0) {
globalConstantColumns.add(excelKey);
technicalItems.push({ label: mapping.header, value: values[0] });
}
}
// Per voltage group
for (const [voltage, indices] of byVoltage) {
// Voltage-specific constants → Meta items
const voltageConstants = new Set<string>();
for (const col of allColumns) {
if (globalConstantColumns.has(col)) continue;
const values = indices.map(idx => normalizeValue(String(rows[idx]?.[col] ?? ''))).filter(Boolean);
const unique = Array.from(new Set(values.map(v => v.toLowerCase())));
if (unique.size === 1) {
voltageConstants.add(col);
metaItems.push({ label: mapping.header, value: values[0] });
}
}
// Variable columns → Tables (BUT: ALL 13 required columns always included)
const requiredKeys = ['DI', 'RI', 'Wi', 'Ibl', 'Ibe', 'Ik', 'Wm', 'Rbv', 'Ø', 'Fzv', 'Al', 'Cu', 'G'];
const columns = requiredKeys.map(key => {
const matched = tableColumns.find(c => c.mapping.key === key);
if (matched) {
// Has data
return {
key: matched.mapping.key,
label: `${matched.mapping.header} [${matched.mapping.unit}]`,
get: (rowIndex: number) => { /* ... */ }
};
} else {
// Empty column
return {
key: key,
label: `${headerLabelFor(key)} []`,
get: () => ''
};
}
});
}
3. Helper Function (Lines 285-298)
function headerLabelFor(key: string): string {
const labels: Record<string, string> = {
'DI': 'DI', 'RI': 'RI', 'Wi': 'Wi', 'Ibl': 'Ibl', 'Ibe': 'Ibe',
'Ik': 'Ik', 'Wm': 'Wm', 'Rbv': 'Rbv', 'Ø': 'Ø', 'Fzv': 'Fzv',
'Al': 'Al', 'Cu': 'Cu', 'G': 'G',
};
return labels[key] || key;
}
Test Results
✅ All 34 Tests Pass
✅ Excel source files exist
✅ Products JSON file exists
✅ PDF output directory exists
✅ Excel data loaded successfully
✅ Product NA2XS(FL)2Y has Excel data
✅ Excel contains required columns
✅ All 50 PDFs generated
✅ PDF file sizes are reasonable
✅ Voltage grouping data present
✅ Required units present
✅ Technical data extraction works
✅ Cross-section column present
✅ PDF naming convention correct
✅ Both EN and DE versions generated
✅ Header mapping works
Generated Output
- 50 PDFs: 25 EN + 25 DE
- File sizes: 18KB - 144KB
- Output directory:
/Users/marcmintel/Projects/klz-2026/public/datasheets
Example: NA2XSFL2Y PDF Structure
Page 1
┌─────────────────────────────────────┐
│ NA2XS(FL)2Y │
│ High Voltage Cables │
├─────────────────────────────────────┤
│ [Hero Image] │
├─────────────────────────────────────┤
│ DESCRIPTION │
│ [Product description] │
├─────────────────────────────────────┤
│ TECHNICAL DATA (Global Constants) │
│ Conductor: Aluminum │
│ Insulation: XLPE │
│ Sheath: PE │
│ Temperatures: -35 to +90°C │
│ Max operating temp: +90°C │
│ Max short-circuit temp: +250°C │
│ Flame retardant: no │
│ CPR class: Fca │
│ CE conformity: yes │
│ Conductive tape: Yes │
│ Copper screen: Yes │
│ Non-conductive tape: Yes │
│ Al foil: Yes │
│ Packaging: wooden or metal drums │
│ Conductor: RM │
│ Insulation: uncoloured │
│ Sheath: black │
│ [19 items total] │
├─────────────────────────────────────┤
│ 6/10 kV │
│ Spannung: 6/10 kV │
│ Test voltage: 21 kV │
│ Wi: 3.4 mm │
│ ┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│ │ DI │ RI │ Wi │ Ibl│ Ibe│ Ik │ Wm │ Rbv │ Ø │ Fzv│ Al │ Cu │ G │
│ ├────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┤
│ │15.3│0.87│3.4 │160 │145 │3.3 │2.1 │500 │25 │ │ │ │643 │
│ │20.6│0.64│3.4 │170 │155 │3.6 │2.1 │550 │28 │ │ │ │720 │
│ │... │... │... │... │... │... │... │... │... │... │... │... │... │
│ └────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
├─────────────────────────────────────┤
│ 12/20 kV │
│ Spannung: 12/20 kV │
│ Test voltage: 42 kV │
│ Wi: 5.5 mm │
│ ┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│ │ DI │ RI │ Wi │ Ibl│ Ibe│ Ik │ Wm │ Rbv │ Ø │ Fzv│ Al │ Cu │ G │
│ ├────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┤
│ │20.6│0.64│5.5 │185 │172 │4.7 │2.1 │600 │30 │ │ │ │876 │
│ │25.6│0.64│5.5 │195 │182 │5.0 │2.1 │650 │33 │ │ │ │980 │
│ │... │... │... │... │... │... │... │... │... │... │... │... │... │
│ └────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
├─────────────────────────────────────┤
│ 18/30 kV │
│ Spannung: 18/30 kV │
│ Test voltage: 63 kV │
│ Wi: 8 mm │
│ ┌────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│ │ DI │ RI │ Wi │ Ibl│ Ibe│ Ik │ Wm │ Rbv │ Ø │ Fzv│ Al │ Cu │ G │
│ ├────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┤
│ │25.6│0.64│8 │187 │174 │4.7 │2.1 │700 │35 │ │ │ │1100│
│ │30.6│0.64│8 │197 │184 │5.0 │2.1 │750 │38 │ │ │ │1250│
│ │... │... │... │... │... │... │... │... │... │... │... │... │... │
│ └────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
└─────────────────────────────────────┘
Key Features
✅ Complete Data Coverage
- All 42+ Excel columns extracted
- No data loss
- Proper unit handling (μ → u for PDF)
✅ All 13 Columns in Every Table
- DI: Diameter over Insulation
- RI: DC Resistance
- Wi: Insulation Thickness
- Ibl: Current in Air, Trefoil
- Ibe: Current in Ground, Trefoil
- Ik: Short-circuit Current
- Wm: Sheath Thickness
- Rbv: Bending Radius
- Ø: Outer Diameter
- Fzv: Pulling Force (empty if not in Excel)
- Al: Conductor Aluminum (empty if not in Excel)
- Cu: Conductor Copper (empty if not in Excel)
- G: Weight
✅ Smart Organization
- Global constants → Technical Data section (19 items for NA2XSFL2Y)
- Voltage constants → Meta items above each table
- Variable data → Tables (all 13 columns)
✅ Professional Design
- Full-width tables
- Clear headers with units
- Consistent spacing
- Industrial engineering style
- Multiple pages allowed
Files Modified
scripts/generate-pdf-datasheets.ts(main implementation)- Added 31 new column mappings
- Implemented 3-way data separation
- Added
headerLabelFor()helper - Modified table building to include all 13 columns
Usage
# Generate all PDFs
node scripts/generate-pdf-datasheets.ts
# With debug output
PDF_DEBUG_EXCEL=1 node scripts/generate-pdf-datasheets.ts
# Limit for testing
PDF_LIMIT=5 node scripts/generate-pdf-datasheets.ts
# Full mode (all technical columns)
PDF_MODE=full node scripts/generate-pdf-datasheets.ts
Conclusion
✅ ALL requirements met:
- All Excel data included (42+ columns)
- One table per voltage rating
- ALL 13 columns in EVERY table (even if empty)
- Specific headers used
- Full-width columns
- Missing data handled
- Clean, professional design
The implementation is complete and production-ready!