Is there any provision to password protect the PDF generated using mlreportgen.dom
Show older comments
I am trying to password protect the document genearted using mlreportgen.com. It may be done using PDFtk but I am not sure how it works with MATLAB, please suggest any method.
Answers (1)
Tejas
on 26 Mar 2024
Edited: Rena Berman
on 16 Jul 2024
Hello Saujandu,
It seems you are interested in finding a method to password-protect your PDF generated from ‘mlreportgen.dom’ in a manner compatible with MATLAB. This can indeed be achieved by utilizing the ‘pikepdf’ library in Python to secure the PDF file, and then invoking this Python script from MATLAB.
Below, is the code snippet that illustrates how Python can be used to password-protect a PDF file.
- Simply provide a new file name and password
- Then save this code into a Python file.
import pikepdf
pikepdf.open("<Name of file to be Password Protected>").save(<"New name for the file>", encryption=pikepdf.Encryption(owner="<OwnerPassword>", user="<UserPassword>", R=4))
After saving the code, execute this Python script from MATLAB using the ‘system’ command.
- Provide the path to Python installation (i.e., the path to the Python executable file) and,
- Provide path to the Python script containing the code snippet above, as inputs to the ‘system’ command.
Here is the syntax for doing so:
system(' "C:\Users\...\Programs\Python\Python38\python.EXE" "Python file name.py" ');
Please refer to the attached documentation to get additional details on the ‘system’ command,
Hope it helps!
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!