Talha912 commited on
Commit
c3213ca
·
verified ·
1 Parent(s): 1adf57b

Update protectpdf.html

Browse files
Files changed (1) hide show
  1. protectpdf.html +16 -9
protectpdf.html CHANGED
@@ -115,10 +115,10 @@
115
  </div>
116
  <div class="toast" id="toast" role="status" aria-live="polite"></div>
117
  <script type="module">
118
- import { createPdfToolkit } from "https://esm.sh/pdfstudio@0.4.0";
119
  try {
120
  window.pdfixToolkit = await createPdfToolkit({
121
- wasmUrl: "https://cdn.jsdelivr.net/npm/pdfstudio@0.4.0/dist/qpdf.wasm"
122
  });
123
  window.pdfixToolkitReady = true;
124
  window.dispatchEvent(new Event("pdfix-toolkit-ready"));
@@ -216,11 +216,9 @@ try {
216
  });
217
  setProgress(82,'Checking encrypted output…');
218
  if(!encryptedBytes || encryptedBytes.length<10) throw new Error('The encryption engine returned an empty output file.');
219
- // Confirm that the output is actually encrypted and requires an opening password.
220
- const info = await window.pdfixToolkit.getInfo(encryptedBytes, { password });
221
- if(!info || !info.encrypted || !info.encryption) {
222
- throw new Error('The engine did not confirm PDF encryption. No file was downloaded.');
223
- }
224
  outputBlob=new Blob([encryptedBytes],{type:'application/pdf'});
225
  if(outputUrl)URL.revokeObjectURL(outputUrl);
226
  outputUrl=URL.createObjectURL(outputBlob);
@@ -239,8 +237,17 @@ try {
239
  }finally{$('protectBtn').disabled=!selectedFile;}
240
  }
241
  function download(){
242
- if(!outputBlob||!outputUrl){toast('Protect the PDF first.');return;}
243
- const a=document.createElement('a');a.href=outputUrl;a.download=safeName($('outputName').value);document.body.appendChild(a);a.click();a.remove();
 
 
 
 
 
 
 
 
 
244
  }
245
  $('protectBtn').addEventListener('click',protect);
246
  $('downloadBtn').addEventListener('click',download);
 
115
  </div>
116
  <div class="toast" id="toast" role="status" aria-live="polite"></div>
117
  <script type="module">
118
+ import { createPdfToolkit } from "https://esm.sh/pdfstudio";
119
  try {
120
  window.pdfixToolkit = await createPdfToolkit({
121
+ wasmUrl: "https://cdn.jsdelivr.net/npm/pdfstudio/dist/qpdf.wasm"
122
  });
123
  window.pdfixToolkitReady = true;
124
  window.dispatchEvent(new Event("pdfix-toolkit-ready"));
 
216
  });
217
  setProgress(82,'Checking encrypted output…');
218
  if(!encryptedBytes || encryptedBytes.length<10) throw new Error('The encryption engine returned an empty output file.');
219
+ // The qpdf WebAssembly lock operation returns the encrypted PDF bytes.
220
+ // Do not block download on a separate metadata-inspection call: that check
221
+ // can fail independently even when encryption itself succeeded.
 
 
222
  outputBlob=new Blob([encryptedBytes],{type:'application/pdf'});
223
  if(outputUrl)URL.revokeObjectURL(outputUrl);
224
  outputUrl=URL.createObjectURL(outputBlob);
 
237
  }finally{$('protectBtn').disabled=!selectedFile;}
238
  }
239
  function download(){
240
+ if(!outputBlob){toast('Protect the PDF first.');return;}
241
+ // Create a fresh object URL at click time for more reliable downloads across browsers.
242
+ const url=URL.createObjectURL(outputBlob);
243
+ const a=document.createElement('a');
244
+ a.href=url;
245
+ a.download=safeName($('outputName').value);
246
+ a.style.display='none';
247
+ document.body.appendChild(a);
248
+ a.click();
249
+ a.remove();
250
+ setTimeout(()=>URL.revokeObjectURL(url),60000);
251
  }
252
  $('protectBtn').addEventListener('click',protect);
253
  $('downloadBtn').addEventListener('click',download);