Android ZXing 在大型 XML 数据集上生成 PDF417 条码

Android ZXing Generate PDF417 Barcode on large XML dataset

我有一个相当大的 XML 数据集,例如:

  <book id=“…” serial_no="8472385" height="210" width="600" books="1">
  <content>
     <barcode encoding="code128c" data1="22" data2="50" description="Barcode 1”>…</barcode>
     <barcode encoding="code128c" data1="510" data2="75" description="Barcode 2”>…</barcode>
     <chapter sections="8" data1="214" data2="12" description=“Info 1”>…</chapter>
     <chapter sections="11" data1="88" data2="63" description=“Info 2”>…</chapter>
     <chapter sections="16" data1="88" data2="42" description=“Info 3”>…</chapter>
     <chapter sections="13" data1="88" data2="83" description=“Info 4”>…</chapter>
     <chapter sections="11" data1="88" data2="105" description=“Info 5“>Mon, 24 Aug 2015, 8:30am</chapter>
     <chapter sections="18" data1="286" data2="120" description=“Info 6”>…</chapter>
     <chapter sections="19" data1="466" data2="12" description=“Info 7“>…</chapter>
     <chapter sections="11" data1="496" data2="26" description=“Info 8“>…</chapter>
     <chapter sections="9" data1="531" data2="28" description=“Info 9“>…</chapter>
     <chapter sections="11" data1="497" data2="12" description=“Info 10“>8:30am</chapter>
     <chapter sections="12" data1="88" data2="147" description=“Info 11“>…</chapter>
     <chapter sections="10" data1="88" data2="125" description=“Info 12”>…</chapter>
     <chapter sections="13" data1="338" data2="158" description=“Info 13”>…</chapter>
     <chapter sections="9" data1="81" data2="192" description="book Id”>…</chapter>
     <chapter sections="8" data1="394" data2="192" description="book Id”>…</chapter>
     <chapter sections="8" data1="140" data2="12" description=“Info 14”>…</chapter>
     <chapter sections="9" data1="132" data2="192" description="" />
     <chapter sections="10" data1="88" data2="177" description=“Info 15“ />
     <chapter sections="12" data1="88" data2="163" description="Some sample data”>…</chapter>
     <chapter sections="8" data1="286" data2="192" description="Time Stamp">2015-08-19 10:00:55</chapter>
     <logo data1="402" data2="37" description="Logo">cache/images/logoSample.pcx</logo>
     <logo_gif data1="402" data2="37" description="Logo">cache/images/book_….gif</logo_gif>
     <chapter sections="12" data1="446" data2="187" description="Price">0.00</chapter>
  </content>
  </book>

我想将其编码为 PDF417 图像并在 android 设备设备上显示它。我已经导入了 ZXing 框架,我目前正在尝试这样的事情:

    ImageView book = (ImageView) mRootView.findViewById(R.id.book_image);
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.x / 2;
    String raw = bookXmlString.replace("<","&lt;").replace(">","&gt;");

    MultiFormatWriter writer = new MultiFormatWriter();
    try {
        Log.e("PDF_417", String.format("w: %d, h: %d, d: %s", width, height, raw));
        BitMatrix bm = writer.encode(raw, BarcodeFormat.PDF_417, width, height);
        Bitmap ImageBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        for (int i = 0; i < width; i++) {//width
            for (int j = 0; j < height; j++) {//height
                ImageBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK : Color.WHITE);
            }
        }            
        book.setImageBitmap(ImageBitmap);
    } catch (WriterException e) {
        Log.e("PDF_417", e.getMessage());
    }

但我不断收到这样的错误:

Unable to fit message in columns

我一直在崩溃这样的网站: - http://www.racoindustries.com/barcodegenerator/2d/pdf417.aspx - http://generator.onbarcode.com/online-pdf417-barcode-generator.aspx

当我编码较少的数据时,我可以毫无问题地获得 PDF417。我也不知道如何设置纠错级别。

我也实现了这里的方法来尝试找出如何最好地设置宽度和高度,没有真正的运气:In a PDF417 barcode where number of columns are fixed, how would I calculate the number of rows required for some text?

总而言之,我要问的是:

  1. 鉴于字符串长度可能不同,如何将此数据编码为 PDF417 条形码?
  2. 如何设置纠错级别?
  3. 设置宽度/高度和行数/列数的最佳方法是什么?

您的样本长度超过 2300 个字符,超出了文本的限制 - 2 个字符 x 900 个代码字 = 1800 个文本字符。参见 https://en.wikipedia.org/wiki/PDF417

您可能需要考虑使用比 XML 更简洁的格式进行数据传输。

只是附加信息 - 如果您需要对大型数据集进行编码,您可以搜索 'PDF417 stitching'。这意味着您将拥有多个 PDF 条形码来保存一个文档,并且需要 reader 将它们放在一起。