TCPDF二维码每次都不一样

发布于 2024-09-16 04:52:01 字数 399 浏览 6 评论 0原文

我在 CakePHP 1.3 中安装了 TCPDF,并使用它生成 QR 码的 PDF。这是一个非常简单的函数,可以创建一个 A9 大小的页面、两个字符串和一个二维码。二维码适用于简单的网址(即“example.com/12345”)。

我可以在浏览器中加载该页面(Safari 使用内置的 PDF 阅读器)。每次重新加载时,二维码都会略有变化。模块尺寸相同,但数据元素发生显着变化。我正在使用“L”数据冗余设置。每次调用时字符串都完全相同,但 QR 发生变化。在观看了多次重新加载后,我相信它只循环了 3 或 4 个版本。

现在这是真正重要的部分,它可以正确扫描。 QR 的每次排列都会在 QR 阅读器中产生完全相同的 url(iPhone4 上的 i-Nigma)

有什么想法吗?我是否做了或错过了一些非常愚蠢和明显的事情?提前致谢!

I've got TCPDF installed in CakePHP 1.3 and am using it to generate a PDF of a QR code. It's a very simple function that creates a A9 sized page, two strings and one QR code. The QR code is for a simple url (ie. 'example.com/12345').

I can load the page in a browser (Safari using it's built in PDF reader.) and each time I reload it, the QR code changes slightly. The module dimensions are the same but the data elements change significantly. I'm using the "L" data redundancy setting. The string is exactly the same each call but the QR changes. After watching a number of reloads I believe it cycles through only 3 or 4 variations.

Now here's the really great part, it scans correctly. Each permutation of the QR results in exactly the same url in the QR Reader (i-Nigma on an iPhone4)

Any ideas? Am I doing or missing something really dumb and obvious? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不羁少年 2024-09-23 04:52:01

似乎 TCPDF 使用的 QR 码生成库使用了一种稍微“懒惰”的方法来创建 QR 码。它从 8 个“掩码”模式中随机选择一个,看看它是否能让代码变得更好。如果满足特定标准,它将使用随机选择的掩码。这会导致每次生成的二维码都可能不同。

显然谷歌使用了更好的算法来选择掩码。可能会检查所有面具并选择最好的一个。这将产生可预测的结果,而不是随机选择的结果。

我将调用 Google Chart API 来检索 PNG,然后将其放入我的 PDF 中,而不是使用内置的 QR 生成器。

Seems that the QR Code generation library used by TCPDF uses a slightly 'lazy' method of creating the QR code. It randomly chooses from any of 8 'mask' patterns to see if it makes the code any better. If it meets a certain criteria, it uses the randomly chosen mask. That results in possibly different QR codes each time.

Apparently Google uses a better algorithm to choose the mask. Probably checks all the masks and chooses the best one. This would result in a predictable outcome instead of a randomly selected one.

I'm going to call the Google Chart API to retrieve a PNG and then place that in my PDF instead of using the built in QR generator.

素年丶 2024-09-23 04:52:01

在 tcpdf 版本 6.2.26 上,运行正常的一种解决方案是更改文件“include/barcodes/qrcode.php”中的第 239 行:
定义('QR_FIND_FROM_RANDOM', 2);

并用下一个替换:
定义('QR_FIND_FROM_RANDOM',无);

On the tcpdf version 6.2.26, one solution that runs ok is change in the file "include/barcodes/qrcode.php" the line 239:
define('QR_FIND_FROM_RANDOM', 2);

And substitute by the next one:
define('QR_FIND_FROM_RANDOM', none);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文