0
一個按鈕應該可以下載即時生成的PDF文件。 PDF由API正確生成,由客戶端代碼處理的文件已損壞,並且不會打開。Vue2:已下載的PDF文件已損壞
的工藝流程:
- 按鈕被點擊
exportDataAsPDFAction
被觸發POST
請求被構建和執行- 響應包含原始PDF文件
- 文件下載是由以下啓動回調邏輯:
this.exportDataAsPDFAction({
gridKey: this.grid.Key,
callback: response => {
let hiddenElement = document.createElement('a');
// This seems to be the problem area
hiddenElement.href = 'data:application/pdf;base64,' + window.btoa(encodeURIComponent(response));
hiddenElement.target = '_blank';
hiddenElement.download = 'Results.pdf';
hiddenElement.click();
}
});
附加:
與CSV執行相同的任務所需的格式作品。唯一的區別存在着編碼和文件擴展名:
hiddenElement.href = 'data:attachment/csv,' + encodeURI(response);
類型錯誤:在「URL」無法執行「createObjectURL」 – Donnie