我可以通过使用带有"EAN13 & UPCA“的"Barby”gem来生成条形码,但是我需要用条形码显示数字,我不知道我在代码中遗漏了什么。
当前生成的条码

读出barby gem文档,但没有成功。
@barcode_value = "123456789123"
full_path = "public/Barcodes/"+@barcode_value+".png"
barcode = Barby::EAN13.new(@barcode_value)
File.open(full_path, 'wb') { |f| f.write barcode.to_png(:margin => 3, :xdim => 2, :height => 50) }生成带编号的条形码。
所需条形码

发布于 2021-08-16 06:27:47
您生成的代码是code 39。您标记为必需的条形码是Code EAN 13,而不是UPC (它们不相同)。使用Ruby创建这样的代码的一种方法是使用API,例如https://mcapi.io/barcode/barcode-api-ruby.php
该应用程序接口托管在RapidAPI上;创建条形码的示例调用:
# Ruby
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://mcapi-barcode.p.rapidapi.com/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["x-rapidapi-key"] = 'YOUR_API_KEY'
request["x-rapidapi-host"] = 'mcapi-barcode.p.rapidapi.com'
request.body = "{
\"data\": \"9501101530003\",
\"type\": 1,
\"size\": 2,
\"format\": \"pdf\"
}"
response = http.request(request)返回的代码将在response.read_body中作为base64编码的PDF (以屏幕截图的形式发布,因为SO不显示PDF):
(免责声明:我们是开发者。)
https://stackoverflow.com/questions/57751782
复制相似问题