Wijmo's PDF API now allows to restrict access to a PDF document with a password and set permissions for certain operations like print or edit. To support this, Wijmo has a new wijmo.pdf.security module added. PdfDocument class also has four new properties: userPassword, ownerPassword, permissions and version.
You need to add the wijmo.pdf.security module on page in order to be able to use these features. This module adds PDF file encryption and PDF permissions capabilities to wijmo.pdf:
import { PdfDocument } from '@grapecity/wijmo.pdf';
import '@grapecity/wijmo.pdf.security';
Lets take a closer look at these new features.
The userPassword property must be specified to restrict access to PDF file with the password:
let doc = new PdfDocument({
userPassword: 'abc'
});
Users with user password are able to decrypt the file and have full access to the document.
The ownerPassword and permissions properties must be specified to set PDF access permissions:
In this example, the permission to copy the file content is given:
let doc = new PdfDocument({
ownerPassword: 'abc',
permissions: {
copying: true
}
});
When only owner password is set, users are able to decrypt and open the document without providing any password, but their access is limited to the operations explicitly permitted by permissions settings. Users with owner password have full access to the document.
When both owner password and user password are set, users with user password are able to decrypt the file but only have limited access to the file according to permissions settings. Users with owner password have full access to the document.
The permissions property allows to specify following settings:
All permissions' properties are Boolean, except the printing property, which is of type PdfPrintPermission and accepts the following values: NotAllowed, AllowLowResolution, AllowHighResolution.
By default, all operations are disallowed. You have to explicitly allow certain operations.
The version property is of type PdfVersion and specifies PDF version of the file.
PDF file of version 1.4 is created here:
let doc = new PdfDocument({
version: PdfVersion.v1_4
});
When the wijmo.pdf.security module is not imported the version property only affects the value of PDF version in the file header. When that module is imported and any of userPassword, ownerPassword properties are set, the version also specifies:
Here's a list of possible version values:
When PDF version 1.7 ExtensionLevel 3 is used, password is truncated to 127 bytes of its UTF-8 representation. In older versions, password is truncated to 32 bytes, and only Latin-1 characters are allowed.
The default version is PDF version 1.3.
Microsoft Internet Explorer 11 is required. Older versions are not supported.
Microsoft Internet Explorer 11 doesn't have String.prototype.normalize method required by wijmo.pdf.security when PDF version 1.7 ExtensionLevel 3 is used. unorm can be used as a polyfill in this case.
The wijmo.pdf.security module has to be added to page in the same way, the documentOptions property is to be used to pass security settings to FlexGridPdfConverter.export method:
import { FlexGridPdfConverter } from '@grapecity/wijmo.grid.pdf';
import '@grapecity/wijmo.pdf.security';
FlexGridPdfConverter.export(grid, 'grid.pdf', {
documentOptions: {
userPassword: 'abc'
}
});