【发布时间】:2023-04-03 15:29:01
【问题描述】:
我想创建一个基于 URL(来自数据库的数据)生成二维码的程序。 二维码不会被存储或保存,只能通过显示二维码的页面上的链接下载。 全部在 PHP 中:) 有人可以帮助我吗? 我还没有找到可下载链接的答案:)
【问题讨论】:
我想创建一个基于 URL(来自数据库的数据)生成二维码的程序。 二维码不会被存储或保存,只能通过显示二维码的页面上的链接下载。 全部在 PHP 中:) 有人可以帮助我吗? 我还没有找到可下载链接的答案:)
【问题讨论】:
这适用于我创建二维码使用 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`
【讨论】: