View pdf from api trick that didn't pan out but this commit has the code in case I ever need it for something else
This commit is contained in:
@@ -631,43 +631,47 @@ export default {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError("uploadLogo", error, route);
|
handleError("uploadLogo", error, route);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
viewPDF(blobData, reportName) {
|
|
||||||
// https://gist.github.com/bondgeek/d44657b2a65e45cb3a645454845fe500
|
|
||||||
|
|
||||||
//possibly useful links:
|
|
||||||
//https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
|
|
||||||
//https://gist.github.com/devloco/5f779216c988438777b76e7db113d05c
|
|
||||||
//https://github.com/eligrey/FileSaver.js
|
|
||||||
const fileName = (reportName && `${reportName}.pdf`) || "myreport.pdf";
|
|
||||||
const newBlob = new Blob([blobData], { type: "application/pdf" });
|
|
||||||
const newWindow = window.open("", reportName, "width=800,height=1200");
|
|
||||||
if (newWindow != null) {
|
|
||||||
setTimeout(() => {
|
|
||||||
const dataUrl = window.URL.createObjectURL(newBlob);
|
|
||||||
const title = newWindow.document.createElement("title");
|
|
||||||
const iframe = newWindow.document.createElement("iframe");
|
|
||||||
|
|
||||||
title.appendChild(document.createTextNode(reportName));
|
|
||||||
newWindow.document.head.appendChild(title);
|
|
||||||
|
|
||||||
iframe.setAttribute("src", dataUrl);
|
|
||||||
iframe.setAttribute("width", "100%");
|
|
||||||
iframe.setAttribute("height", "100%");
|
|
||||||
|
|
||||||
newWindow.document.body.appendChild(iframe);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
// For Firefox it is necessary to delay revoking the ObjectURL
|
|
||||||
window.URL.revokeObjectURL(dataUrl);
|
|
||||||
}, 100);
|
|
||||||
}, 100);
|
|
||||||
} else {
|
|
||||||
alert(
|
|
||||||
"To display reports, please disable any pop-blockers for this page and try again."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//this worked on all platforms except phone browser
|
||||||
|
//safest way is to just trigger a window open to download the pdf which is what I did
|
||||||
|
//Keeping this in a commit in case I need to revisit it later
|
||||||
|
// ,
|
||||||
|
// viewPDF(blobData, reportName) {
|
||||||
|
// // https://gist.github.com/bondgeek/d44657b2a65e45cb3a645454845fe500
|
||||||
|
|
||||||
|
// //possibly useful links:
|
||||||
|
// //https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
|
||||||
|
// //https://gist.github.com/devloco/5f779216c988438777b76e7db113d05c
|
||||||
|
// //https://github.com/eligrey/FileSaver.js
|
||||||
|
// const fileName = (reportName && `${reportName}.pdf`) || "myreport.pdf";
|
||||||
|
// const newBlob = new Blob([blobData], { type: "application/pdf" });
|
||||||
|
// const newWindow = window.open("", reportName, "width=800,height=1200");
|
||||||
|
// if (newWindow != null) {
|
||||||
|
// setTimeout(() => {
|
||||||
|
// const dataUrl = window.URL.createObjectURL(newBlob);
|
||||||
|
// const title = newWindow.document.createElement("title");
|
||||||
|
// const iframe = newWindow.document.createElement("iframe");
|
||||||
|
|
||||||
|
// title.appendChild(document.createTextNode(reportName));
|
||||||
|
// newWindow.document.head.appendChild(title);
|
||||||
|
|
||||||
|
// iframe.setAttribute("src", dataUrl);
|
||||||
|
// iframe.setAttribute("width", "100%");
|
||||||
|
// iframe.setAttribute("height", "100%");
|
||||||
|
|
||||||
|
// newWindow.document.body.appendChild(iframe);
|
||||||
|
|
||||||
|
// setTimeout(() => {
|
||||||
|
// // For Firefox it is necessary to delay revoking the ObjectURL
|
||||||
|
// window.URL.revokeObjectURL(dataUrl);
|
||||||
|
// }, 100);
|
||||||
|
// }, 100);
|
||||||
|
// } else {
|
||||||
|
// alert(
|
||||||
|
// "To display reports, please disable any pop-blockers for this page and try again."
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
//---------------
|
//---------------
|
||||||
|
|
||||||
//new functions above here
|
//new functions above here
|
||||||
|
|||||||
Reference in New Issue
Block a user