我有一个相当大的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">$100.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("<","<").replace(">",">");
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());
}
但我继续收到这样的错误:
无法在列中填写消息
我一直在崩溃这样的网站: - 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?
总之,我在问:
答案 0 :(得分:2)
您的样本长度超过2300个字符,超出了文本限制 - 2个字符x 900个代码字= 1800个文本字符。见https://en.wikipedia.org/wiki/PDF417
您可能需要考虑使用比XML更简洁的格式进行数据传输。
只是附加信息 - 如果您需要编码大型数据集,可以搜索“PDF417拼接”。所有这些意味着您将拥有多个PDF条形码来存放文档,并且需要读者将它们组合在一起。