Skip to content

Commit

Permalink
Fix saved PDF filename
Browse files Browse the repository at this point in the history
  • Loading branch information
photown committed Dec 26, 2023
1 parent f1d2fde commit 6facdfa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function onPageLoad() {

view.setOnPdfFileChosenListener(async function (pdfFile: File) {
await readFileAsArrayBuffer(pdfFile).then(function (fileData: ArrayBuffer) {
loadPdf(fileData);
loadPdf(pdfFile.name, fileData);
});
});

Expand Down Expand Up @@ -75,15 +75,16 @@ function onPageLoad() {
return response.arrayBuffer();
})
.then((arrayBuffer) => {
loadPdf(arrayBuffer);
const fileName = url.split("/").pop() || "mypdf.pdf";
loadPdf(fileName, arrayBuffer);
})
.catch((error) => {
console.error("Error downloading file:", error);
alert(`Error downloading file: ${error}`);
});
}

async function loadPdf(fileData: ArrayBuffer) {
async function loadPdf(fileName: string, fileData: ArrayBuffer) {
currentPage = 1;
var originalToActualRatio: number = -1;

Expand Down Expand Up @@ -203,7 +204,7 @@ function onPageLoad() {
overlays,
/* rotateBy = */ 90
);
loadPdf(savedBytes);
loadPdf(fileName, savedBytes);
});

view.setOnSaveClickedListener(async function () {
Expand All @@ -212,7 +213,7 @@ function onPageLoad() {

const bytes = await pdfDocument.savePdf(formInputValues, overlays);

view.downloadBlob(bytes, "testfile");
view.downloadBlob(bytes, "privatepdf-" + fileName);
});

view.setOnInsertTextClickListener();
Expand Down

0 comments on commit 6facdfa

Please sign in to comment.