This commit is contained in:
2020-09-02 22:56:56 +00:00
parent 9128b425c7
commit d4a6401eb2
2 changed files with 35 additions and 39 deletions

View File

@@ -617,6 +617,38 @@ export default {
} catch (error) {
handleError("uploadLogo", error, route);
}
},
viewPDF(blobData, reportName) {
// Adapted from: https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
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."
);
}
}
//---------------

View File

@@ -701,11 +701,11 @@ Handlebars.registerHelper('loud', function (aString) {
//test open new window for test url
// window.open("http://localhost:7575/api/v8/report/poc", "_blank");
let test = await window.$gz.api.upsert("report/post-poc", {
let pdf = await window.$gz.api.upsert("report/post-poc", {
name: "Demko"
});
console.log("Test is ", test);
showFile(test, "myreport");
window.$gz.api.viewPDF(pdf, "myreport");
//
return;
@@ -925,40 +925,4 @@ async function fetchReportData(vm) {
vm.reportData = res.data;
}
}
const showFile = (blobData, reportName) => {
// Adapted from: https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/
const fileName = (reportName && `${reportName}.pdf`) || "myreport.pdf";
const newBlob = new Blob([blobData], { type: "application/pdf" });
const newWindow = window.open("", reportName, "width=800,height=1200");
console.log(newWindow);
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."
);
}
};
</script>