SetPermissions
Set permissions for PDF-document.
func (document *Document) SetPermissions(userPassword string, ownerPassword string, permissions Permissions) error
Parameters:
- userPassword - user password
- ownerPassword - owner password
- permissions - bitmask of allowed PDF permissions (combine flags using
|):
type Permissions int32
const (
PrintDocument Permissions = 1 << 2 // 4
ModifyContent Permissions = 1 << 3 // 8
ExtractContent Permissions = 1 << 4 // 16
ModifyTextAnnotations Permissions = 1 << 5 // 32
FillForm Permissions = 1 << 8 // 256
ExtractContentWithDisabilities Permissions = 1 << 9 // 512
AssembleDocument Permissions = 1 << 10 // 1024
PrintingQuality Permissions = 1 << 11 // 2048
)
Return:
- error - contains an error or nil if absent
Example:
package main
import "github.com/aspose-pdf/aspose-pdf-go-cpp"
import "log"
func main() {
// New creates a new PDF-document
pdf, err := asposepdf.New()
if err != nil {
log.Fatal(err)
}
// Close() releases allocated resources for PDF-document
defer pdf.Close()
// SetPermissions(userPassword, ownerPassword, permissions) sets permissions for PDF-document
err = pdf.SetPermissions(
"userpass",
"ownerpass",
asposepdf.PrintDocument|
asposepdf.ModifyContent|
asposepdf.FillForm,
)
if err != nil {
log.Fatal(err)
}
// SaveAs(filename string) saves previously opened PDF-document with new filename
err = pdf.SaveAs("sample_with_permissions.pdf")
if err != nil {
log.Fatal(err)
}
}