0
我需要幫助,將從html2canvas承諾獲得的數據url分配給downloadPdf()函數中的listingReportImg。html2Canvas無法及時檢索pdf生成的數據url
預期結果:
listingReportImg = data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ...
日誌
listingReportImg:: undefined
listing report uri::
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg ...
listings.component.html
<button (click)="downloadPdf()">Print</button>
個listings.component.ts
listingReportToDataUrl(){
let listingReport = document.getElementById('listing-report');
console.log("listingReport:: ", listingReport);
html2canvas(listingReport, { useCORS: true })
.then(function (canvas) {
let listingReportUri = canvas.toDataURL('image/png');
console.log("listing report uri::", listingReportUri);
return listingReportUri;
});
}
downloadPdf(){
let listingReportImg = this.listingReportToDataUrl();
console.log("listingReportImg:: ", listingReportImg);
pdfMake.createPdf(listingReport(listingReportImg)).download('test.pdf');
}
這工作就像一個魅力。非常感謝。 :) – absingharora