Ejemplo n.º 1
0
    $embed_file = new MappedFile($input_path . "my_stream.txt");
    $mystm = new FilterReader($embed_file);
    $page_dict->Put("Contents", $doc->CreateIndirectStream($mystm, new FlateEncode(new Filter())));
}
//encrypt the document
// Apply a new security handler with given security settings.
// In order to open saved PDF you will need a user password 'test'.
$new_handler = new SecurityHandler();
// Set a new password required to open a document
$user_password = "******";
$new_handler->ChangeUserPassword($user_password);
// Set Permissions
$new_handler->SetPermission(SecurityHandler::e_print, true);
$new_handler->SetPermission(SecurityHandler::e_extract_content, false);
// Note: document takes the ownership of new_handler.
$doc->SetSecurityHandler($new_handler);
// Save the changes.
echo "Saving modified file...\n";
$doc->Save($output_path . "secured.pdf", 0);
$doc->Close();
// Example 2:
// Opens an encrypted PDF document and removes its security.
$doc = new PDFDoc($output_path . "secured.pdf");
//If the document is encrypted prompt for the password
if (!$doc->InitSecurityHandler()) {
    $success = false;
    echo "The password is: test\n";
    for ($count = 0; $count < 3; $count++) {
        echo "A password required to open the document.\n" . "Please enter the password:";
        $password = trim(fgets(STDIN));
        if ($doc->InitStdSecurityHandler($password, strlen($password))) {