Local Repot-嵌入Barcode

  目前專案內的報表在呈現Barcode時,所以使用的方式是用Image的External的屬性,透過http取得Barcode。例:http://www.barcodes4.me/barcode/c128a/00000001.png?IsTextDrawn=1

image

使用內嵌的方式

在Code Project瞄到了一篇如何內嵌Barcode的介紹文章。照著作了一篇,並調整成之後專案要使用的方式。

1.Nuget 參考BarcodeLib

image

2.撰寫代理類別 BarcodeProxy.cs


public class BarcodeProxy
    {
        private BarcodeLib.Barcode Barcode;
        public BarcodeProxy()
        {
            this.Barcode = new BarcodeLib.Barcode();
        }
        public byte[] Render(string value)
        {
            Barcode.Alignment = BarcodeLib.AlignmentPositions.CENTER;
            Barcode.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
            Barcode.IncludeLabel = true;
            Barcode.AlternateLabel = value;
            Barcode.RotateFlipType = RotateFlipType.Rotate180FlipXY;
            var image = Barcode.Encode(BarcodeLib.TYPE.CODE128A, value, Color.Black, Color.White, 250, 90);
            using (var ms = new MemoryStream())
            {
                image.Save(ms, ImageFormat.Png);
                return ms.ToArray();
            }
        }
    }

3.報表屬性-加入參考

本例為專案自己 ps: dll的位置在哪不重要,此動作只是要assemble namespace。在執行時的只要Local Report所在的bin內有相關dll即可。
image

4.報表屬性-加入代碼

呼叫在第2個步驟撰寫的代理類別
image

Public Function Convert(Text As String) As Byte()
            Dim barcodeProxy As New ReportBarcodeRenderLab.BarcodeProxy
           Return barcodeProxy.Render(Text)
       End Function

加入完畢後,建置會失敗

image













要將報表屬性建置行為設為none,建置才會成功


image

5.新增圖片-指定方法

image source選擇Database,並在field指定在第4步驟的轉檔方法

image

6.測試程式

image

原始碼:https://github.com/kimx/ReportBarcodeRenderLab

參考來源

https://www.codeproject.com/articles/789254/how-to-embed-barcodes-in-your-ssrs-report

這個網誌中的熱門文章

IIS 設定只允許特定IP進入