[英]How to write the data received as response from the Fetch API into my pdf using jsPDF?
I am trying to write the title of a website into my pdf.我正在尝试将网站标题写入我的 pdf。 This is my code:
这是我的代码:
const doc = new jsPDF();
fetch('https://api.codetabs.com/v1/proxy?quest=https://arunachaltimes.in/index.php/2022/04/27/mein-requests-vaishnaw-to-start-murkongselek-pasighat-broad-gauge-project/')
.then(
function (response) {
response.text().then(function(data) {
const parser = new DOMParser();
const htmldoc = parser.parseFromString(data, "text/html");
let title = htmldoc.getElementsByTagName("title")[0].innerText;
console.log(title) //shows the correct value
doc.text(10,10, title);
})
}
)
.catch(function(err) {
console.log(err);
})
doc.save('myfile.pdf'); //completely blank pdf
The pdf is completely empty?! pdf 完全是空的?! Why?
为什么? When I
console.log(title)
, then the value shows, but I think the pdf is downloaded before the text is written into the pdf.当我
console.log(title)
,然后值显示,但我认为 pdf 是在文本写入 pdf 之前下载的。 How do I fix it?我如何解决它?
try this, doc.text( title,10,10);试试这个,doc.text(title,10,10); doc.text( title,10,10);
doc.text(标题,10,10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.