这是我的情况,我正在尝试获取Dynamics CRM上的自定义操作产生的pdf字符串,并让用户可以打开预览,然后,如果他愿意,可以从Chrome浏览器下载PDF文件Pdf Viewer,但如果我尝试下载它,则下载会因网络错误而被阻止。 这是打开预览的代码
function (params)
{
// Success
if (quest.toString() === "true") {
alert("Documento Creato");
this.location.reload(true);
}
else if (quest.toString() === "false") {
var file = b64toBlob(params.Pdf, "application/pdf");
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(file);
alert("Documento Creato");
} else {
var blobUrl = window.URL.createObjectURL(blobToFile(file,
params.PdfFilename));
window.open(blobUrl);
}
}
reloadPage();
},
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, { type: 'application/pdf' });
return blob;
}
function blobToFile(theBlob, fileName) {
//A Blob() is almost a File() - it's just missing the two properties below
//which we will add
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return theBlob;
}
`
感谢您的帮助。