Add MICR font diagnostic logging to trace load failure
This commit is contained in:
@@ -97,10 +97,9 @@ function formatMicrLine(routingNo, accountNo, checkNo) {
|
|||||||
*/
|
*/
|
||||||
function generateCheckPdf(account, checks, fields) {
|
function generateCheckPdf(account, checks, fields) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log(`[pdf] MICR font path: ${MICR_FONT_PATH}`);
|
||||||
const hasMicrFont = fs.existsSync(MICR_FONT_PATH);
|
const hasMicrFont = fs.existsSync(MICR_FONT_PATH);
|
||||||
if (!hasMicrFont) {
|
console.log(`[pdf] MICR font exists: ${hasMicrFont}`);
|
||||||
console.warn(`MICR font not found at ${MICR_FONT_PATH}. MICR line will use fallback font.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const doc = new PDFDocument({
|
const doc = new PDFDocument({
|
||||||
size: [
|
size: [
|
||||||
@@ -112,7 +111,14 @@ function generateCheckPdf(account, checks, fields) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (hasMicrFont) {
|
if (hasMicrFont) {
|
||||||
|
try {
|
||||||
doc.registerFont('MICR', MICR_FONT_PATH);
|
doc.registerFont('MICR', MICR_FONT_PATH);
|
||||||
|
console.log('[pdf] MICR font registered successfully');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[pdf] MICR font registration failed: ${err.message}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(`[pdf] MICR font not found — falling back to Courier`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buffers = [];
|
const buffers = [];
|
||||||
@@ -206,10 +212,15 @@ function generateCheckPdf(account, checks, fields) {
|
|||||||
const micrPos = pt(0.3, MICR_Y_IN);
|
const micrPos = pt(0.3, MICR_Y_IN);
|
||||||
|
|
||||||
if (hasMicrFont) {
|
if (hasMicrFont) {
|
||||||
|
try {
|
||||||
doc.font('MICR').fontSize(12).fillColor('#000000')
|
doc.font('MICR').fontSize(12).fillColor('#000000')
|
||||||
.text(micrLine, micrPos.x, micrPos.y, { lineBreak: false });
|
.text(micrLine, micrPos.x, micrPos.y, { lineBreak: false });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[pdf] Failed to render MICR font on slot ${slot}: ${err.message}`);
|
||||||
|
doc.font('Courier').fontSize(10).fillColor('#000000')
|
||||||
|
.text(micrLine, micrPos.x, micrPos.y, { lineBreak: false });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback: Courier approximation (will not scan, but useful for dev)
|
|
||||||
doc.font('Courier').fontSize(10).fillColor('#000000')
|
doc.font('Courier').fontSize(10).fillColor('#000000')
|
||||||
.text(micrLine, micrPos.x, micrPos.y, { lineBreak: false });
|
.text(micrLine, micrPos.x, micrPos.y, { lineBreak: false });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user