Crystal报表中的条形码

时间:2018-12-16 15:49:19

标签: c# crystal-reports barcode crystal-reports-2008 barcode-printing

我无法在Crystal报告中打印条形码... 我必须打印该条形码

enter image description here

在我的crystal报告中,我将此公式与field绑定

BarcodeEAN13({@x},"")

@x是

{TabA.cod_ean13}

那是我的数据库表TabA中的varchar字段

现在,我的c#方法将datasource设置为水晶报表并导出到PDF中。 代码如下:

string root_path = ConfigurationManager.AppSettings["Percorso_RPT"];
            string spath = Utility.PathCombine(root_path, cod_etic + "D.rpt");

            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(spath);

            List<DatiStampa> lista = new List<DatiStampa>();
            lista.Add(ds);

            cryRpt.SetDataSource(Utility.DataTableFromIEnumerable(lista));

            //export in pdf     
            cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, path);
            cryRpt.Close();
            cryRpt.Dispose();

这是我在barcode field中获得的

enter image description here

我已经尝试过更改字体,但是无事可做...

我做错了什么?

3 个答案:

答案 0 :(得分:0)

条形码是否在报告预览中正确显示?还是预览和pdf导出均不正确? 如果仅在pdf导出中,则可能是字体大小调整问题,可以使用此处讨论的注册表设置来解决:https://kenhamady.com/cru/archives/2503

或者,here中列出的第三方Crystal Reports用户功能库之一允许您使用图像生成条形码。这样就消除了对字体的依赖。

答案 1 :(得分:0)

在另一个框架中已经有类似的问题。原来,字体太大,文本框太小。之后,一小部分丢失了,条形码无法正确读取。

答案 2 :(得分:0)

EAN-13条形码之所以这样命名,不是因为它们支持13位数字,而是因为有12位数字的数据和1个校验和字符。不管上面第一个示例条形码下的文字是什么,扫描仪返回的数据都是'8009197111119'。这是有道理的,因为'800919711111'的校验和为'9'。

“ 80”表示EAN13代码已分配给公司代码可能为“ 09197”的意大利公司。接下来的五个字符“ 11111”是产品代码。

EAN条形码类似于美国人所说的UPC符号,很难将其实现为字体。整个符号前半部分中数字的符号段与后半部分中的字符相反,是黑白的。这就是为什么无论哪种软件生成用于生成条形码的字符代码的原因,前半部分似乎都使用“字母”,而下半部分则使用正确的后6位数字。

再加上生成最终校验和数字所需的相当复杂的算法,使得没有一些代码来操纵您使用的任何字体就无法生成EAN-13条形码。您上面附加的第二个图像与EAN字体不同,看起来更像Code39。字体大小不正确并被裁剪。

我不太熟悉c#,所以我做了一个小工具,可以帮助您在JavaScript中测试代码。

// The MIT License (MIT)

// Copyright (c) 2018, Notionovus, LLC.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

// Generic arrays for drawing 5-bit graphics. Building blocks for all barcode symbologies
// Painstakingly derived gobblety-goop, but essentially the two middle sections of image data unique to each graphic
var array5bit_A = new Array ( 'f//AAAAAAAAAAAAAAAAAAAA', 'f//AAAAAAAAAAAAAAAAAAAB', 'f//AAAAAAAAAAAAAAEAAAD/',
 'f//AAAAAAAAAAAAAAEAAAAA', 'f//AAAAAAAAAQAAAP8AAAAA', 'f//AAAAAAAAAQAAAP8AAAAB', 'f//AAAAAAAAAQAAAAAAAAD/',
 'f//AAAAAAAAAQAAAAAAAAAA', 'f//AAABAAAA/wAAAAAAAAAA', 'f//AAABAAAA/wAAAAAAAAAB', 'f//AAABAAAA/wAAAAEAAAD/',
 'f//AAABAAAA/wAAAAEAAAAA', 'f//AAABAAAAAAAAAP8AAAAA', 'f//AAABAAAAAAAAAP8AAAAB', 'f//AAABAAAAAAAAAAAAAAD/',
 'f//AAABAAAAAAAAAAAAAAAA', 'QD/AAD/AAAAAAAAAAAAAAAA', 'QD/AAD/AAAAAAAAAAAAAAAB', 'QD/AAD/AAAAAAAAAAEAAAD/',
 'QD/AAD/AAAAAAAAAAEAAAAA', 'QD/AAD/AAAAAQAAAP8AAAAA', 'QD/AAD/AAAAAQAAAP8AAAAB', 'QD/AAD/AAAAAQAAAAAAAAD/',
 'QD/AAD/AAAAAQAAAAAAAAAA', 'QD/AAAAAAAA/wAAAAAAAAAA', 'QD/AAAAAAAA/wAAAAAAAAAB', 'SL/AADeAAAA/gAAAAIAAAD+',
 'QD/AAAAAAAA/wAAAAEAAAAA', 'QD/AAAAAAAAAAAAAP8AAAAA', 'QD/AAAAAAAAAAAAAP8AAAAB', 'QD/AAAAAAAAAAAAAAAAAAD/',
 'QD/AAAAAAAAAAAAAAAAAAAA');
var array5bit_B = new Array ( 'US0CAuSD38g', 'UUYCA7QBErs', 'ajEDAm49ReY', 'UUoCA+juogg', 'bjEDAjQrOn0', 'bkoDA3iPVH4',
 'ajUDAt82atY', 'UU4CA1nljTg', 'cjEDAghkmFU', 'ckoDA0TA9lY', 'izUEAhrxcbg', 'ck4DAxY8F10', 'bjUDAlvFFR8', 'bk4DAxdhexw',
 'ajkDAr7LFAw', 'UVICAyQ+UJI', 'TTECAq7UnEM', 'TUoCA+Jw8kA', 'ZjUDAmZGozo', 'TU4CA7CME0s', 'ajUDAvnk9E4', 'ak4DA7VAmk0',
 'ZjkDAtle3bI', 'TVICAxOyzrM', 'STUCAqHeHtM', 'SU4CA+16cNA', 'h6QEAZKdo54', 'SVICA62zYxM', 'RTkCAqx1lb4', 'RVICA/z3WM0',
 'QT0CAkdoxRU', 'KFYBA46vJCA');

// Painstakingly derived gobblety-goop, but essentially the front, back and mid-matter common to all barcode images...
var stringStart = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAACCAQAAADLaIVbAAAANUlEQVQIHQEqANX/A';
var stringMid = 'AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAA';
var stringEnd = 'AAAAASUVORK5CYII=" width="';

function genBarcode(inputString,intWidth,intHeight) { // Input is a long string of 1's and 0's, output is the HTML <img> stack
// Pads to the last character to ensure length is divisible by 5
   var intRawmod = inputString.length % 5; // Modulo 5 remainder
   if (intRawmod > 0) for (var i = 0; i < 5 - intRawmod; i++) inputString += "0"; // If not evenly divisible, pad with zeroes
   var arraySeq = new Array (intChunks = inputString.length / 5); // Create array for as many chunks as are now in input string

   for (var i = 0; i < intChunks; i++) arraySeq[i] = parseInt(inputString.substr(i * 5, 5), 2); // Converts string of 1's and 0's to integer array

// Takes integer array and converts to "<img ...>" graphics for display
   var resultString = "";
   for (var i = 0; i < arraySeq.length; i++) {
   	resultString += stringStart + array5bit_A[arraySeq[i]] + stringMid + array5bit_B[arraySeq[i]] + stringEnd + intWidth + '" height="' + intHeight + '">';
   }
   return resultString;
}
///////////////////////////////////////////
// Symbology-specific arrays

// UPC Specific Arrays
var arrayCodeEANBin, arrayStructEAN;
arrayCodeEANBin = [ [ '0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011' ], [ '0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111' ], [ '1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100' ] ];
arrayStructEAN = ['000000', '001011', '001101', '001110', '010011', '011001', '011100', '010101', '010110', '011010'];

///////////////////////////////////////////
// Global Variables
var strRaw = "";
var strText = "";

///////////////////////////////////////////
// Symbology-specific functions
function funcEAN() { // EAN-13
var intSumOdd = 0, intSumEven = 0, intCheck, i, j, strStruct;

// Compute check digit and add it to raw string
 for (i = 0; i < 12; i += 2) {
  intSumEven += parseInt(strText[i]);
  intSumOdd += parseInt(strText[i+1]);
 }
 intCheck = ((intSumOdd * 3) + intSumEven) % 10;
 if (intCheck > 0) {
 	intCheck = 10 - intCheck;
 }
 strText += intCheck;

// Converts Code EAN array into string of 1's and 0's
 strRaw = "101";
// First six bar sequences
 strStruct = arrayStructEAN[strText[0]];
 for (i = 1; i < 7; i += 1) {
   strRaw += arrayCodeEANBin[strStruct[i-1]][strText[i]];
 }
// Middle sequence
 strRaw += "01010";
// Last six bar sequences, including check digit
 for (i = 0; i < 6; i += 1) {
  strRaw += arrayCodeEANBin[2][strText[i+7]];
 }
 strRaw += "101";
} // End EAN-13


var buttonBarcode = document.getElementById("btnGenBar");
buttonBarcode.onclick = function () {
 var intHt = intWd = 0;
 var strImages = "";
 document.getElementById("textImages").value = strImages;
 intWd = document.getElementById("textWidth").value;
 intHt = document.getElementById("textHeight").value;
 strText = document.getElementById("textBarcode").value;
 funcEAN();
 document.getElementById("result").innerHTML = strImages = genBarcode(strRaw,intWd,intHt);
 document.getElementById("textImages").value = strImages;
 document.getElementById("textRaw").value = strRaw;
 document.getElementById("textImages").select();
}
<head>
<title>EAN-13 Barcodes in vanilla JavaScript</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
  <h1>EAN-13 Barcodes written in vanilla JavaScript</h1>
  <h4>Enter text (a 12-digit number), enter a non-ridiculous height in pixels, enter a width between 4 (so small) and 40 (gigantor) and press the button. Magic will ensue. Print page or copy HTML out of box and paste it where it will do some good.</h4>  
 <div id="inputForm">
 	Enter Text:&nbsp;<input type="text" id="textBarcode" placeholder="12 Digit Number" tabindex=1/>
 	&nbsp;Height:&nbsp;<input type="text" id="textHeight" size="3" placeholder="40-100" maxlength="5" tabindex=2/>
 	&nbsp;Width:&nbsp;<input type="text" id="textWidth" size="3" placeholder="4.0-40.9" maxlength="5" tabindex=3/>
 	&nbsp;
 	<input type="button" id="btnGenBar" value="Generate Barcode" tabindex=4/>
 </div>
 <p></p>
 <div id="result"></div>
 <p></p>
 <textarea rows="30" cols="110" id="textImages" tabindex=0></textarea>
 <p></p>
 <textarea rows="3" cols="110" id="textRaw" tabindex=0></textarea>
</body>