java 从扫描的 PDF 中读取二维码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5537167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Read QR Code from scanned PDF
提问by Jo?o Simas
I'm trying to insert and read qrcode's from PDF files. To create/read qr codes from images i'm using zxing projectand to manipulate the pdf i'm using Big Faceless PDF.
我正在尝试从 PDF 文件中插入和读取 qrcode。要从图像中创建/读取 qr 代码,我正在使用zxing 项目并操作我正在使用的 pdf Big Faceless PDF。
Everything works well if i create the QR Code, insert into my pdf, and then read the images from the pdf and convert the correct one to QR Code. However, if i try to to read images from a scanned document (with a qr code sticker attach to it), i cannot obtain the qr code image from the pdf (the only image i can get, using Big Faceless PDF, is the document it self).
如果我创建 QR 码,插入到我的 pdf 中,然后从 pdf 中读取图像并将正确的图像转换为 QR 码,则一切正常。但是,如果我尝试从扫描的文档中读取图像(附有二维码贴纸),则无法从 pdf 中获取二维码图像(使用 Big Faceless PDF,我可以获得的唯一图像是文档它自己)。
Does anyone knows a Java library to search in pdf files for qr codes?
有谁知道在 pdf 文件中搜索二维码的 Java 库?
Thanks for you help
谢谢你的帮助
采纳答案by Mike B
The only reliable way to do this is to convert the PDF page to a bitmap, then using something like zxing to scan the entire page for the barcode. Extracting the individual images that make up the page won't work on every document: the barcode may be created using graphics operations rather than as an embedded image (that's how we do it), or if you PDF was scanned from a paper source as you've described, it will usually be one big image.
唯一可靠的方法是将 PDF 页面转换为位图,然后使用 zxing 之类的工具扫描整个页面以查找条形码。提取构成页面的单个图像不适用于每个文档:条形码可能是使用图形操作创建的,而不是作为嵌入图像(我们就是这样做的),或者如果您的 PDF 是从纸质来源扫描的你已经描述过,它通常是一个大图像。
Once you've got the PDF converted to a bitmap, ZXing should be able to do this, at least in theory. Naturally I'd recommend sticking with us for the conversion to bitmap ;-)
一旦您将 PDF 转换为位图,ZXing 应该能够做到这一点,至少在理论上是这样。当然,我建议坚持使用我们转换为位图 ;-)
If ZXing is having trouble finding the code, make sure it has enough white-space around it - you need 4 clear modules on all sides, so for smaller codes it should be about 10% of the width of the code in whitespace around the code, to help it scan.
如果 ZXing 在查找代码时遇到问题,请确保它周围有足够的空白 - 您需要在所有侧面都有 4 个清晰的模块,因此对于较小的代码,它应该是代码周围空白中代码宽度的 10% 左右,帮助它扫描。
Cheers... Mike (CTO@BFO)
干杯......迈克(CTO@BFO)
回答by JKippson
I have gotten this to work:
我已经得到了这个工作:
- Use
Imagick
to converts pdfs into pngs - Use
Zxing
\QrReader
to read the QR data
- 使用
Imagick
到PDF文件转换成PNG图片 - 使用
Zxing
\QrReader
读取二维码数据