How to put QR Code to PDF in WordPress without plugin

So I needed to create a pdf certificate of membership for every user in my wordpress website, and I wanted to put QR code to the pdf certificate so that the certificate can be validated.

The QR code data is the page url of the user details. It is expected that the certificate can be validated by scanning the the QR code, and it will be redirected to the url of the user page. There, the certificate can be validated whether the certificate is true or fake.

After trying QR Codes plugins and Print to PDF plugins, I finally found the best solutions:

To generate QR Code

To generate QR code, I finally found a way, that is not to use plugin. That is because dynamics QR code generated by plugins is in form of SVG file, and SVG file cannot be rendered as image in the PDF.

The solution is:

To use direct image html tag combined with QR code API from Here. (I got the tutorial from Here).

Here is the sample:

<img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=ACCOUNT_NUMBER_HERE">

All I need to do is to replace the data, that is “ACCOUNT_NUMBER_HERE”, with my own data. My data in this case is the dynamic url of the user page.

To output into PDF

To output into PDF, I use a plugin PDF Generator for WP. It is a free plugin. All you need to do is to customise the page. Put anything you want to print on the pdf in that page.

In my case, I use gravityview to display the user data. Using gravityview, I can set dynamic user id based on the currently logged in user.

Using the combination of the above methods, I can successfully print high quality pdf containing dynamic data and dynamic QR code.

My conclusion:

The best way to print or output dynamic QR code to pdf in wordpress is to use QR Code API in tag combined with free page/post to pdf plugin.

Hopefully that helps.

Thanks.

Leave a Reply