从C#中的字节数组生成PDF417条码 [英] Generating a PDF417 barcode from a Byte array in c#

查看:163
本文介绍了从C#中的字节数组生成PDF417条码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种从字节数组生成PDF417条码的方法.

I need a way of generating PDF417 barcodes from byte arrays.

我发现有很多可以生成条形码的SDK,但是它们都希望将字符串作为数据而不是字节数组,但是不幸的是,由于我需要符合预先存在的标准,因此这是不可能的

I have found numerous SDKs that can generate barcodes but all of them expect a string as the data instead of a byte array, unfortunately this isn't a possibility since I need to conform to a pre-existing standard

预先感谢

我尝试过的代码,应Wyatt Earp的要求.

Code that I have tried, as requested by Wyatt Earp.

    /// <summary>
    /// Writes the barcode data to a specified location
    /// </summary>
    /// <param name="data">Data of the barcode</param>
    /// <param name="Location">Location to save barcode</param>
    public void Write(byte[] data, string Location)
    {
        ///* Keep Automation Barcode Creator
        KeepAutomation.Barcode.Crystal.BarCode KABarcode = new KeepAutomation.Barcode.Crystal.BarCode();
        KABarcode.Symbology = KeepAutomation.Barcode.Symbology.PDF417;
        KABarcode.PDF417DataMode = KeepAutomation.Barcode.PDF417DataMode.Auto;
        KABarcode.CodeToEncode = data;
        KABarcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
        KABarcode.generateBarcodeToImageFile(Location);
        //*/

        ///* BarcodeLib Creator
        BarcodeLib.Barcode.PDF417 barcodeLibBar = new BarcodeLib.Barcode.PDF417();
        barcodeLibBar.Data = data;
        var BarLibImage = barcodeLibBar.drawBarcode();
        BarLibImage.Save(Location);
        //*/

        ///* PQScan.Barcode Creator
        PQScan.BarcodeCreator.Barcode PQScanBarcode = new PQScan.BarcodeCreator.Barcode();
        PQScanBarcode.BarType = PQScan.BarcodeCreator.BarCodeType.PDF417;
        PQScanBarcode.Data = data;
        PQScanBarcode.PictureFormat = System.Drawing.Imaging.ImageFormat.Png;
        var PQScanImage = PQScanBarcode.CreateBarcode();
        PQScanImage.Save(Location);
        //*/
    }          

这些都不会生成,因为它们都希望将字符串作为条形码数据,所以我需要给它们一个字节[]

None of these will build since they all expect strings as the barcode data, I need to give them a byte[]

不幸的是,我已经从其他SDK的代码中删除了代码,但是它们都倾向于遵循相同的模式.

Unfortunately I already deleted the code from the other SDK's but all of them tend to follow the same pattern.

我尝试过的SDK的综合列表是:

Comprehensive list of SDK's I have tried are:

  • SharpPdf417
  • Zxing
  • PQScan.BarcodeCreator
  • TBarcode
  • KeepAutomation.Barcode
  • BarcodeLib

所有这些SDK仅接受字符串作为条形码数据,我需要读取的字节数组是输入到该void中的字节数组,

All of these SDKs only accept a string as the barcode data, I need the byte array that is read to be the byte array that is inputted into this void,

我无法为您提供确切的字节数组,但是它的大小为454,并且在整个字节数组中使用了几种不同的编码方法.

I am unable to give you the exact byte array, but it has a size of 454 and uses several different encoding methods throughout the byte array.

推荐答案

谢谢,但是由于我需要将其保留为Wyatt Earps的格式,因此它对我没有用,但似乎可以使用为其他人.

Thanks, but Since I needed to keep it in the format it already was in Wyatt Earps Answer didn't work for me but it does seem like it would work for others.

对于我来说,我设法找到的Aspose .Barcode 具有一项功能,该功能使我可以直接从字节数组生成条形码,而不必进行转换.

For me I managed to find that Aspose.Barcode had a feature that would allow me to generate barcodes straight from the byte array instead of having to convert it.

下面是我所用的代码,以防任何人感兴趣

Below is the code I use incase it is of interest to anyone

    /// <summary>
    /// Writes the barcode data to a specified location
    /// </summary>
    /// <param name="data">Byte data of barcode</param>
    /// <param name="Location">Location to save barcode</param>
    public void Write(byte[] data, string location)
    {
        //Define the barcode builder with properties
        BarCodeBuilder builder = new BarCodeBuilder()
        {
            SymbologyType = Symbology.Pdf417,
            Rows = 30
        };

        //Set Data
        builder.SetBinaryCodeText(data);

        //Generate Barcode
        var barcodeBitmap = builder.GenerateBarCodeImage();

        //Save it to disk
        barcodeBitmap.Save(location);
    }                    

这篇关于从C#中的字节数组生成PDF417条码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆