dart_pdf
dart_pdf copied to clipboard
Protect a PDF from modification
Is there a solution for preventing the user to modify the PDF ?
Yes, you'll need the encryption library that can password-protect modifications. Note: That works only if the reader software is OK with implementing that restriction, like Acrobat Reader.
Thank you, do you have an example of usage with a PDF ?
Something like:
final pdf = Document();
// Declare the encryption options
pdf.document.encryption = PdfEncryptionAES(
pdf.document,
owner: 'MySecureSecretPassword', // The owner password (has all rights)
accessFlags: <PdfAccessFlags>{
PdfAccessFlags.Copy, // The user with no password can only copy/paste and print
PdfAccessFlags.Print,
},
level: PdfAESLevel.high,
);
pdf.addPage(
Page(
build: (Context context) {
return Text('This text is encrypted using AES 256');
},
),
);
final File file = File('encrypted.pdf');
await file.writeAsBytes(await pdf.save());
Which library are you using ? PdfEncryptionAES does not exist with library 'encrypt', and the library 'encrypt' does not manage pdf files...
This library: https://pub.nfet.net/pdf_crypto/