lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.36k stars 666 forks source link

Add PDF support #181

Closed Daniel-Steinberger closed 3 years ago

Daniel-Steinberger commented 5 years ago

Hey, I've been using your awesome library for a project of mine. But since I need the code as PDF I first built a solution using reportlab to convert the SVG to PDF. But then I thought it would be a good excuse to learn some more about creating PDFs. So I did, so I made a very simple PDF-Image-Module that's only able to output QR-Codes, but that was all I needed.

If you like it, you can mainline it, I think PDF is a very useful format to have. I use it to include QR-Codes in TeX documents and since I perfer vector-data over pixel-data in my print-products, this might be something other people might benefit from, too.

heuer commented 3 years ago

But since I need the code as PDF I first built a solution using reportlab to convert the SVG to PDF.

Since Pillow supports PDF as output format, you can save the Pillow Image directly as PDF:

>>> import qrcode
>>> qr = qrcode.make('Test')
>>> qr.save('test.pdf', format='pdf')

test.pdf

heuer commented 3 years ago

No offense, I haven't seen the differences, Pillow creates not a PDF path, see https://github.com/lincolnloop/python-qrcode/pull/203#issuecomment-696353463

maribedran commented 3 years ago

It seems the example above solves the issue. Closing the PR. @Daniel-Steinberger feel free to reopen if you still think it's a valid use case.