if (true) { echo "Replacing the content stream, use Flate compression...\n"; // Get the page dictionary using the following path: trailer/Root/Pages/Kids/0 $page_dict = $doc->GetTrailer()->Get("Root")->Value()->Get("Pages")->Value()->Get("Kids")->Value()->GetAt(0); // Embed a custom stream (file mystream.txt) using Flate compression. $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;