Skip to content

Commit

Permalink
convert file with filereader
Browse files Browse the repository at this point in the history
  • Loading branch information
hschell-cortado committed Aug 2, 2022
1 parent 7eafa61 commit 1c58a5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/taskpane/taskpane.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@
</div>
</div>
</div>
<!-- dev client 9I9DPCHGvsXjraQfwuRzL7OlVpqiryJ19yfYLeLH
<!-- tst client dp8gisibeh5xoNkeZewjBQqjPaUUgAEP8MUlvbT8
prod client WnjHlEm0TYYJDt8dovTqUDJMa4ifB2C9eehABA1U
authapihosturl="account.dev.azdev.ezeep.com"
printapihosturl="printapi.dev.azdev.ezeep.com"-->
<ezp-printing
clientid="WnjHlEm0TYYJDt8dovTqUDJMa4ifB2C9eehABA1U"
clientid=""9I9DPCHGvsXjraQfwuRzL7OlVpqiryJ19yfYLeLH
redirecturi="https://localhost:3000/authRedirect.html"
trigger="custom"
filetype="pdf"
Expand Down
31 changes: 25 additions & 6 deletions src/taskpane/taskpane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,31 @@ async function onGotAllSlices(docdataSlices) {
docdata = docdata.concat(docdataSlices[i]);
}
fileData = docdata;
const filearray = new Uint8Array(fileData);
const filestring = filearray.toString();
// console.log(filestring);
ezpPrinting.setAttribute("filedata", filestring);
ezpPrinting.setAttribute("filename", "test.pdf");
if (authorized) ezpPrinting.open().then(() => (loadingSection.style.display = "none"));
let filearray = new Uint8Array(fileData);
let reader = new FileReader();
let filestring: string | ArrayBuffer;
reader.onload = () => {
filestring = reader.result;
console.log("filestring in taskpane:");
console.log(filestring);
ezpPrinting.setAttribute("filedata", filestring);
ezpPrinting.setAttribute("filename", "test.pdf");
if (authorized) ezpPrinting.open().then(() => (loadingSection.style.display = "none"));
// delete filestring from memory
fileData = null;
filearray = null;
filestring = null;
};

// read filedata as binary string
reader.readAsBinaryString(new Blob([filearray]));
// write to file
// const blob = new Blob([filearray], { type: "application/pdf" });
// const url = URL.createObjectURL(blob);
// const a = document.createElement("a");
// a.href = url;
// a.download = "test.pdf";
// a.click();
}

async function openAuthDialog() {
Expand Down

0 comments on commit 1c58a5c

Please sign in to comment.