Product: webviewer
Product Version:8.9.0
Please give a brief summary of your issue: Need to remove a password from a protected file and save added annotations
Please describe your issue and provide steps to reproduce it:
I’m using a function to check whether a pdf file is password protected or not and i’m coding it with javascript and vue 2, that function allows me to get the password that i pass to UI.loadDocument in this way
WebViewer({
path: '/js/WebViewerNew/lib',
css: '/css/pdftron.css',
fullAPI: that.filePassword !== ''
}, document.getElementById('webviewer'))
.then((instance) => {
instance.UI.loadDocument(that.initialDoc, {
password: that.filePassword
});
this works and i’m able to open the document no problem, and i’m able to add and save annotations to it with this code.
const doc = documentViewer.getDocument();
xfdfString = await that.annotationManager.exportAnnotations({useDisplayAuthor: false});
const data = await doc.getFileData({
// saves the document with existing annotations in it
xfdfString
});
const arr = new Uint8Array(data);
const blob = new Blob([arr], {type: 'application/pdf'});
this code works fine as well and i save all annotations to the document no problem, however the final document is still protected and i would like to remove the password from the document while keeping the changes, the issue is that the threads i have seen and the tutorials i have been recommended to check all use PDFDoc and PDFNet functions which doesn’t work for me, in some cases i get an empty file and in other cases i get an error saying an error happened because data is corrupt, also i noticed that those functions seem to create a new document and the purpose is to put the content of the original file into the new file without the password, if i understand correctly, which is fine since i have no problem with that as long i send the same info to the backend and can keep the annotations, original content and remove the password.
Now this is the code i’m using after reading the docs about this operation
const doc2 = await PDFNet.PDFDoc.createFromBuffer(arr);
await doc2.initSecurityHandler();
await doc2.removeSecurity();
const docbuf = await doc2.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_linearized);
so i need a hand with a code template and an explanation that tells me the following
-
is is absolutely necessary to create a new document in order to remove password? if yes then at what point should the new document be created? in what way? from what source, url or buffer?
-
is it possible to remove password first and then pass that document to the first and/or second code i posted?
-
are there any other ways to remove the password?
-
what is the recommended order for, remove password, save annotations and convert to blob, to get the result i need.
PD: please don’t direct me to other links talking about the operation without providing a working template as i have checked them and have not been helpful for me,