0

I would like to create a program that generates a QR code based on a URL (data from a database). The QR code will not be stored or saved, but only downloadable via a link on the page displaying the QR code. All in PHP :) Could someone help me ? I haven't found my answer for the downloadable link :)

Roro
  • 11
  • 2
  • There are a lot of examples here on SO, do none of them help? https://stackoverflow.com/questions/5943368/dynamically-generating-a-qr-code-with-php, https://stackoverflow.com/questions/49519102/how-to-generate-a-qr-code-using-php, https://stackoverflow.com/questions/47931876/generate-qr-code-with-php-qr-code-library, https://stackoverflow.com/questions/45520988/creating-a-qr-code-with-a-centered-logo-in-php-with-php-qr-code-generator ... – Don't Panic May 09 '21 at 12:33

1 Answers1

1

This works for me in creating the QR code use API:-

https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl={data}
In place of data use the data which you want to convert into a QR code.

Code:-
<div id="data_id">
<div class="col">
<?php
echo '<img src="https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl={data}">';
?>
</div>
</div>
<button id="downloadid" class="btn btn-small btn-primary">Download</button>


Script For the Downloading the QR code image:-

<script>
var d = document.getElementById("downloadid");
d.addEventListener("click", function(e) {
var div = document.getElementById("data_id");
var opt = {
margin: [20, 20, 20, 20],
filename: `filname.pdf`,
image: {
   type: 'jpg',
   quality: 0.98
},
html2canvas: {
  scale: 2,
  useCORS: true
},
jsPDF: {
unit: 'mm',
format: 'letter',
orientation: 'portrait'
}
};
html2pdf().from(div).set(opt).save();
});
</script>`enter code here`