开发者

TCPDF QR Code is different all the time

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 e开发者_开发问答xactly 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!


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.


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);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜