You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++实现打印页面添加MICR行技术求助

Fixing MICR Line Generation for PCL Output

Let's walk through correcting your code to meet the MICR formatting requirements, then note key considerations for your future C# PDF rewrite.

1. Correct MICR String Construction

Your current code hardcodes the transit number and misses the required MICR symbols. Here's the updated version that aligns with your specifications:

// 创建MICR字符串
string stmtTransCode = FindTransCode(vStrPage);
stmt->SetStmtTransCode(stmtTransCode);
MBStatement* mbStmt = dynamic_cast<MBStatement*>(stmt);
mbStmt->m_strMICR = "";

if (!stmtTransCode.empty()) {
    // 替换为你实际获取transit号码的方法(比如GetTransitNum())
    string transitNum = stmt->GetTransitNum(); 
    string accountNum = stmt->GetAccNum();

    // 用IDAutomation转账号码符号(|: 和 :|)包裹transit号码
    mbStmt->m_strMICR += "|:" + transitNum + ":|";
    // 添加account号码及ON-US符号(||')
    mbStmt->m_strMICR += " " + accountNum + "||'";
    // 添加trans code
    mbStmt->m_strMICR += " " + stmtTransCode;
}

Key Fixes:

  • Replaced the hardcoded transit number with dynamic retrieval (update GetTransitNum() to match your actual method name)
  • Wrapped the transit number in the required IDAutomation transit symbols |: ... :|
  • Added the ON-US symbol ||' immediately after the account number
  • Used a single dynamic_cast to clean up repeated casting logic

2. Update the MICR Printing Method

Your current code uses an OCRA font (for OCR recognition), but MICR lines require a dedicated MICR font (like IDAutomation's MICR E-13B) to be readable by check processing equipment. Also, fix the return value to properly indicate success:

BOOL MBStmtWriter::WriteMICRLine(string m_MICRLine) {
    if (m_MICRLine.empty()) {
        return FALSE; // 空MICR行不打印
    }

    // 替换为你的MICR专用字体名称(确保打印机已安装该字体)
    string micrFontCmd = m_printer.getFont("IDAutomationMICRFont"); 
    string positionCmd = m_printer.getXYPosCMD(2000, 3225);

    // 发送字体设置、位置定位和MICR字符串到打印机
    m_printer.WriteCMD(micrFontCmd + positionCmd);
    m_printer.WriteCMD(m_MICRLine);

    return TRUE; // 成功打印返回TRUE
}

Critical Checks:

  • Confirm your printer has the IDAutomation MICR font installed (either as a resident font or soft font loaded at runtime)
  • Verify the XY coordinates (2000, 3225) place the MICR line in the standard bottom position of the page (adjust if needed)

3. Notes for Future C# PDF Rewrite (JDF Control)

When migrating to C# and PDF output with JDF:

  • Use a PDF library that supports embedding custom MICR fonts (like iTextSharp or PdfSharp)
  • Ensure the MICR line is placed in the industry-standard position (typically the bottom 0.5–1 inch of the page)
  • JDF will handle job instructions like paper tray selection, but you’ll need to map MICR font embedding and positioning logic to your PDF generation workflow

内容的提问来源于stack exchange,提问作者lsieting

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:55:48