D365 SSRS打印报表一维码实现

通常SSRS报表 一维码打印需求可通过设置文本字体(如Code 128等)来实现。但产生的一维码 扫码的效果不如人意。 在此不再多提。

本文指在通过外部工具来实现一维码的生成,通过图片加在到SSRS报表中,扫码效果有较大改善,且支持字母 数字 特殊字符 等。

网上推荐实现一维码的工具包 有 barcodelib  zxing.net 。

博主使用  zxing.net   实现。

  1. 下载 zxing.net  dll文件 NuGet Gallery | ZXing.Net 0.16.10

下载后的文件为.nupkg   可修改为.zip  通过压缩文件打开

 选择符合365环境使用的  .NET Framework 的版本

  2. 新建C# 项目

 

编写创建一维码的静态方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace BarCodeV2
{
    public class BarCode
    {
        //System.Drawing.Bitmap
        public static System.Drawing.Bitmap createBarCode(String _barCode,Boolean _includeLabel,
            int width ,int height) {
            ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
            writer.Format = ZXing.BarcodeFormat.CODE_128;
            ZXing.Common.EncodingOptions options = new ZXing.Common.EncodingOptions();
            options.Width = width;
            options.Height = height;
            options.Margin = 2;
            options.PureBarcode = _includeLabel;
            writer.Options = options;
            
            return writer.Write(_barCode);
        }

    }
}

  

   3. FO项目引入C# 项目

  

private container BarCode(str code)
    {
        
        try
        { 
            using (System.Drawing.Bitmap bm = BarCodeV2.BarCode::createBarCode(code,true,150,50))
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                bm.Save(stream, System.Drawing.Imaging.ImageFormat::Png);
                return Binary::constructFromMemoryStream(stream).getContainer();
            }
        }
        catch (Exception::CLRError)
        {
            throw error(CLRInterop::getLastException().ToString());
        }
        
    }
    

  

 public void processReport()
    {
        List idList;
        Enumerator em;

        ProdTable         prodTable;

        contract = this.parmDataContract() as ProdTableReportContract;
        idList   = contract.parmList();
        em       = idList.getEnumerator();

        while(em.moveNext())
        {
            prodTable           = ProdTable::find( em.current() );
            reportTb.Clear(); 
            reportTb.ProdId_QrCode  = this.BarCode(reportTb.ProdId);
            reportTb.Insert();
        }
        
    }

 SSRS使用图片。 

 

   4. 打印效果

 

posted @ 2025-07-12 19:54  枯藤老树流水人家  阅读(20)  评论(0)    收藏  举报