在线效果:https://codepen.io/13476075014/pen/VwJdGvz?editors=1010
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <!-- 引入axios --> <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.7.5/axios.min.js"></script> <div id="qrcode"></div> <!-- 要打印的iframe --> <iframe id="wordPreview" style="display: none;"></iframe> <script type="text/javascript"> //二维码 // var qrcode = new QRCode(document.getElementById("qrcode"), { // text: "http://jindo.dev.naver.com/collie", // width: 128, // height: 128, // colorDark: "#000000", // colorLight: "#ffffff", // correctLevel: QRCode.CorrectLevel.H // }); //处理预览打印的效果 axios('https://gimg3.baidu.com/search/src=http%3A%2F%2Fpics6.baidu.com%2Ffeed%2Fc995d143ad4bd113bf33fe87473c2c014afb052e.jpeg%40f_auto%3Ftoken%3D06f223bda9ac455d6ae194dd03271730&refer=http%3A%2F%2Fwww.baidu.com&app=2021&size=f360,240&n=0&g=0n&q=75&fmt=auto?sec=1725123600&t=3e135da5639d7d6e70617babba5f2240', { responseType: 'blob' }, {}).then(response => response.data ) .then(blob => { const url = window.URL.createObjectURL(blob); const iframe = document.getElementById('wordPreview'); // iframe.src = url; // Print the iframe content iframe.contentWindow.document.body.innerHTML = `<img src="${url}"/>` setTimeout(() => { iframe.contentWindow.print(); }) }) .catch(e => console.error('Error:', e)) </script> </body> </html>
标签:baidu,预览,接口,blob,iframe,pdf,document,com From: https://www.cnblogs.com/chun321/p/18388025